Trying to populate an Outlook Calendar from excel but can't seem to get the correct calendar populated.
I want to populate an outlook calendar named "MyCal" but the code below only populates the calendar named "calendar" which is a default.
Again works great as long as I am populating the default but will not populate a specifically named calendar.
I am unsure it it is pst issue or??? but very frustrating.
Any help would be appreciated>
The below code was from a very old post on vbaexpress;
Code to populate Outlook Calendar from excel:
I want to populate an outlook calendar named "MyCal" but the code below only populates the calendar named "calendar" which is a default.
Again works great as long as I am populating the default but will not populate a specifically named calendar.
I am unsure it it is pst issue or??? but very frustrating.
Any help would be appreciated>
The below code was from a very old post on vbaexpress;
Code to populate Outlook Calendar from excel:
VBA Code:
Sub AddAppointments()
'http://www.vbaexpress.com/forum/archive/index.php/t-53311.html
Dim olApp As Object
Dim olNs As Object
Dim olStore As Object
Dim olCal As Object
Dim objAppt As Object
Dim lastrow As Long
Dim xlSheet As Worksheet
Dim i As Long
Dim strStart As String
Dim strEnd As String
Const strCalendar As String = "MyCal"
'On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")
If olApp Is Nothing Then Set olApp = CreateObject("Outlook.Application")
'On Error GoTo 0
If Not olApp Is Nothing Then
Set olNs = olApp.GetNamespace("MAPI")
olNs.logon
For Each olStore In olNs.Folders
For Each olCal In olStore.Folders
If olCal.Name = strCalendar Then
Set xlSheet = Sheets(1)
With xlSheet
lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = 2 To lastrow
strStart = CDate(xlSheet.Range("B" & i)) & Chr(32) & CDate(xlSheet.Range("C" & i))
strEnd = CDate(xlSheet.Range("D" & i) & Chr(32) & CDate(xlSheet.Range("E" & i)))
Set objAppt = olCal.Items.Add(1)
With objAppt
.Subject = xlSheet.Range("A" & i)
.Start = strStart
.End = strEnd
.Body = xlSheet.Range("G" & i)
.Categories = xlSheet.Range("F" & i)
.ReminderSet = True
.AllDayEvent = False
.BusyStatus = 1
.Save
End With
Next i
End With
Exit For
Exit For
End If
Next olCal
Next olStore
End If
lbl_Exit:
Set olApp = Nothing
Set olNs = Nothing
Set olStore = Nothing
Set olCal = Nothing
Set objAppt = Nothing
Set xlSheet = Nothing
Exit Sub
End Sub