0
votes

Simple enough line here:

Set navFol = navGroup.NavigationFolders.Add(cal)

This works as expected for any local calendars, but it instantly crashes Outlook if "cal" is a shared calendar. Anyone know a workaround to move shared calendars around between navigation folders? I'm quite new to VBA, just hacking my way around to get a macro to do a simple something for me -- or at least something which really should be simple if not for this.

I doubt it matters, but just in case, "cal" is being set in a for loop by iterating through a list of EntryIDs like so:

Set cal = Application.GetNamespace("MAPI").GetFolderFromID(str)

And it's not the variable assignment that's failing there (which is why the above line should be irrelevant). I can do anything else with the calendar whether or not it's shared: read the name, grab appointments from it, etc. Outlook just apparently does not like using shared calendars as arguments for NavigationFolders.Add().

EDIT: I'm talking about NON-default calendars shared via sharing invitations. GetDefaultSharedFolder or the like isn't what I want.

1

1 Answers

0
votes

Try to use the GetSharedDefaultFolder method of the Namespace class to get the shared folder instead.

Sub ResolveName()  
 Dim myNamespace As Outlook.NameSpace  
 Dim myRecipient As Outlook.Recipient  
 Dim CalendarFolder As Outlook.Folder 
 Set myNamespace = Application.GetNamespace("MAPI")  
 Set myRecipient = myNamespace.CreateRecipient("Eugene Astafiev")  
 myRecipient.Resolve  
 If myRecipient.Resolved Then  
  Call ShowCalendar(myNamespace, myRecipient)  
 End If  
End Sub 

Sub ShowCalendar(myNamespace, myRecipient)  
 Dim CalendarFolder As Outlook.Folder 
 Set CalendarFolder = _  
 myNamespace.GetSharedDefaultFolder _  
 (myRecipient, olFolderCalendar)  
 CalendarFolder.Display  
End Sub

The Add method of the NavigationFolders class adds the specified Folder, as a NavigationFolder object, to the end of the NavigationFolders collection.