How to Import Excel Appointments to Outlook via VBA Using Combined Date and Time Values
Question details
The user needs to automate the creation of Outlook appointments using data from an Excel worksheet where date and time are stored in separate columns.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Automating Outlook calendar events using an Excel VBA macro, but encountering errors when the source file uses separate fields for start and end times.
- Observed behavior
- A Type Mismatch error occurs in the VBA script because Outlook requires a complete date-and-time object, while the code attempts to assign separated date and time values from the worksheet directly to Outlook properties.
Verify that your Excel columns for StartDate, StartTime, and EndTime contain valid date and time formats rather than plain or unrecognized text strings.
Combine Date and Time Values in VBA using DateValue and TimeValue
Use VBA's built-in conversion functions to merge separate date and time worksheet cells into a single Date object recognized by Outlook.
When transferring data from Excel into Outlook using VBA, Outlook's '.Start' and '.End' properties strictly expect a combined DateTime variable. If your Excel sheet stores the date in one column (e.g., Column 2) and the time in another (e.g., Column 3), attempting to assign them as-is will trigger a Type Mismatch error.
Determine the exact column numbers for your dates and times in your spreadsheet. For example, Subject in Column 1, StartDate in Column 2, StartTime in Column 3, and EndTime in Column 4.
In your VBA editor, create a combined start date variable by adding the converted values. Use this syntax: startDate = DateValue(ws.Cells(iRow, 2).Value) + TimeValue(ws.Cells(iRow, 3).Value).
Similarly, combine the start date and the end time for the appointment's conclusion: endDate = DateValue(ws.Cells(iRow, 2).Value) + TimeValue(ws.Cells(iRow, 4).Value).
Apply the new combined variables to the Outlook appointment object in your macro using .Start = startDate and .End = endDate.

Use WPS Spreadsheet to Manage and Run VBA Macros
WPS Office Spreadsheet provides excellent support for VBA and macro execution. You can smoothly write and edit scripts to interact with applications like Outlook and manage your automated tasks in a highly compatible environment.
- 1. Open your macro-enabled file: Launch WPS Spreadsheet and open your .xlsm workbook that contains the appointment data and macro.
- 2. Open the VBA Editor: Go to the 'Tools' tab on the top ribbon and click on 'Visual Basic Editor' to access your macro scripts.
- 3. Update your code: Locate your Outlook automation macro and apply the DateValue and TimeValue corrections to your variables.
- 4. Run the macro: Click the 'Run' button (or press F5) within the VBA editor to execute your code and successfully export the appointments to Outlook.

Frequently Asked Questions
Why am I getting a Type Mismatch error when assigning dates to Outlook in VBA?
This error occurs because Outlook's appointment .Start and .End properties require a combined date-and-time object. If your code attempts to push separate date or time strings directly to these properties, or if the source cells contain unreadable text formats instead of valid dates, VBA throws a Type Mismatch error.
How do I ensure my Excel cells are formatted as valid dates for VBA?
Select the cells containing your dates, right-click, and choose 'Format Cells'. Ensure the 'Date' format is applied. Do the same using the 'Time' format for your time columns. This helps VBA's DateValue and TimeValue functions parse the data correctly.
Will DateValue and TimeValue work if my cells contain text?
Yes, DateValue and TimeValue are designed to convert recognized text representations of dates and times (e.g., '25/07/2024' or '09:30') into standard date serial numbers that VBA can process, provided the text follows a standard regional format.




