olApp = Nothing ?
Kutools for Excel is a powerful add-in that frees you from performing time-consuming operations in Excel, such as combine sheets quickly, merge cells without losing data, paste to only visible cells, count cells by color and so on. 300+ powerful features / functions for Excel 2019, 2016, 2013, 2010, 2007 or Office 365!
It enables tabbed browsing, editing, and managing of Microsoft Office applications. You can open multiple documents / files in a single tabbed window, such as using the browser IE 8/9/10, Firefox, and Google Chrome. It's compatible with Office 2019, 2016, 2013, 2010, 2007, 2003 or Office 365. Demo
Kutools for Outlook is a powerful add-in that frees you from time-consuming operations which majority of Outlook users has to perform daily! It can save your time from using Microsoft Outlook 2019, 2016, 2013, 2010 or Office 365!
Kutools for Word is a powerful add-in that frees you from time-consuming operations which majority of Word users have to perform daily! It can save your time from using Microsoft Word / Office 2019, 2016, 2013, 2010, 2007, 2003 or Office 365!
Restores the old look and menus of Office 2003 to Microsoft Office 2019, 2016, 2013, 2010, 2007 or Office 365. Don’t lose time in finding commands on the new Ribbon. Easy to deploy to all computers in enterprises and organizations.
Supposing, you have a table of appointment data in an Excel worksheet as following screenshot shown, now, you want to import these data into the Outlook calendar. How could you deal with this job quickly?
To create appointments from Excel data, you can apply the following VBA code, please do as this:
1. Launch Outlook and hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.
2. Click Insert > Module, and paste the following code in the Module Window.
VBA code: Import excel data to appointment:
Public Sub CreateOutlookApptz() Dim xAppointmentItem As Outlook.AppointmentItem Dim xNameSpace As Outlook.NameSpace Dim xCalendarFld As Outlook.MAPIFolder, xSubFolder As Outlook.MAPIFolder Dim xCalendarStr As String Dim I As Long Dim xFileDialog As FileDialog Dim xFilePath As String Dim xExcelApp As Excel.Application Dim xWb As Workbook Dim xWs As Worksheet On Error GoTo Err_Execute Set xExcelApp = New Excel.Application Set xFileDialog = xExcelApp.FileDialog(msoFileDialogFilePicker) With xFileDialog .Title = "Select a file" .Filters.Add "Microsoft Excel", "*.xlsx" End With If xFileDialog.Show = 0 Then Exit Sub xFilePath = xFileDialog.SelectedItems(1) Set xWb = xExcelApp.Workbooks.Open(xFilePath) Set xNameSpace = Outlook.Application.Session Set xCalendarFld = xNameSpace.GetDefaultFolder(olFolderCalendar) I = 2 Set xWs = xWb.Worksheets.Item(1) xCalendarStr = xWb.Name If FolderExist(xCalendarFld, xCalendarStr) = False Then Set xSubFolder = xCalendarFld.Folders.Add(xCalendarStr, olFolderCalendar) Else Set xSubFolder = xCalendarFld.Folders(xCalendarStr) End If Do Until Trim(xWs.Cells(I, 1).Value) = "" Set xAppointmentItem = xSubFolder.Items.Add(olAppointmentItem) With xAppointmentItem .Start = xWs.Cells(I, 5) + xWs.Cells(I, 6) .End = xWs.Cells(I, 7) + xWs.Cells(I, 8) .Subject = xWs.Cells(I, 1) .Location = xWs.Cells(I, 2) .Body = xWs.Cells(I, 3) .BusyStatus = olBusy .ReminderMinutesBeforeStart = xWs.Cells(I, 9) .ReminderSet = True .Categories = xWs.Cells(I, 4) .Save End With I = I + 1 Loop Set xAppointmentItem = Nothing Set olApp = Nothing xExcelApp.Quit Set xExcelApp = Nothing MsgBox "Import successfully!", vbInformation, "Kutools for Outlook" Exit Sub Err_Execute: MsgBox "An error occurred - Exporting items to Calendar.", vbInformation, "Kutools for Outlook" End Sub Function FolderExist(CalFolder As Folder, FolderName As String) As Boolean Dim I As Integer Dim xSubFolder As Folder For I = 1 To CalFolder.Folders.Count Set xSubFolder = CalFolder.Folders.Item(I) If xSubFolder.Name = FolderName Then FolderExist = True Exit Function End If Next I End Function
3. Still in the Microsoft Visual Basic for Applications window, click Tools > References to go to the References-Project1 dialog box, and check Microsoft Excel Object Library option from the Available References list box, see screenshot:
4. Then click OK button, now, press F5 key to run this code, and a Select a file window is displayed, please select the excel file you want to import to Outlook, see screenshot:
5. And then click OK, a prompt box is popped out as follows:
6. Then click OK, the Excel data has been imported into the calendar as following screenshot shown: