Referencing a shared calendar

2019-09-12 17:07发布

问题:

I tried to run the code from this question: Exporting Outlook calendar data to Excel file - Shared calendars and VBA

My code modification.

Set olNS = olApp.GetNamespace("MAPI")
Set myCalItems = olNS.CreateRecipient("theOtherUser")
myCalItems.Resolve
myCalItems.GetSharedDefaultFolder 

I got error 13 Type mismatch. I've testing different combinations without result.

I tested this example too: MSDN link

This info is useful but not enough: http://www.snb-vba.eu/

I need to export shared MS Outlook's calendars (with Exchange server) to MS Excel.

These calendars are shared to me and other people.

I run MS Office 2010 version.

回答1:

Error 13 in VBA means a type mismatch. See Type mismatch (Error 13) for more information.

You need to use the following code instead:

Sub ShowSharedFolder(OutlookApplication As Outlook.Application) 
   Dim myNamespace As Outlook.NameSpace 
   Dim myRecipient As Outlook.Recipient 
   Dim CalendarFolder As Outlook.Folder 

   Set myNamespace = OutlookApplication.GetNamespace("MAPI") 
   Set myRecipient = myNamespace.CreateRecipient("theOtherUser") 
   myRecipient.Resolve 

   If myRecipient.Resolved Then 
     Set CalendarFolder = myNamespace.GetSharedDefaultFolder(myRecipient, olFolderCalendar) 
     CalendarFolder.Display 
   End If 
End Sub