0

I am trying to create an event in Outlook using data from Excel.

Dim objOutlook As Object
Dim ObjAppt As Object
Dim objNamespace As Object
Dim objFolder As Object
Dim OpenMAPIFolder As Object
Dim objCalendar As Object
   
Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set objFolder = objNamespace.GetDefaultFolder(9).Folders("Calendar")
Set ObjAppt = objFolder.Items.Add 'create task item
With ObjAppt
    .Body = Range("A1")
    .Start = Range("A17")
    .End = Range("B17")
    .AllDayEvent = True
    .ReminderSet = True
    .ReminderMinutesBeforeStart = 1440
    .Save
End With

Set ObjAppt = Nothing
Set objFolder = Nothing
Set objNamespace = Nothing
Set objOutlook = Nothing

It says that the folder name is incorrect.

Community
  • 1
  • 1
Inquisitor
  • 15
  • 1
  • 7
  • I guess what I need to know is how can I get to the correct folder/calendar? I looked at Outlook, and it clearly says that my default calendar is just called Calendar. I don't know why it is having trouble finding it – Inquisitor Feb 18 '20 at 20:01
  • https://stackoverflow.com/a/49121400/4539709 – 0m3r Feb 18 '20 at 21:21

1 Answers1

0

To get to the default Calendar folder try

objNamespace.GetDefaultFolder(olFolderCalendar)

NameSpace.GetDefaultFolder method (Outlook)

also see Reference Outlook folder from Excel

https://stackoverflow.com/a/41476442/4539709

0m3r
  • 12,286
  • 15
  • 35
  • 71