问题
I've got some VBa code that opens the Calendar in a new window, but I now need it to display the shared calendars that I've already got setup, but the only code I can find Creates a new shared calendar in the new window i've just created;
Sub DispCalendars()
Dim myOlApp As Outlook.Application
Dim myNms As Outlook.NameSpace
Dim myFolder As Outlook.MAPIFolder
Dim myRecipient As Outlook.Recipient
Dim myExplorer As Outlook.Explorer
Dim SharedFolder As Outlook.MAPIFolder
Set myOlApp = CreateObject("Outlook.Application")
Set myNms = myOlApp.GetNamespace("MAPI")
Set myFolder = myNms.GetDefaultFolder(olFolderCalendar)
Set myExplorer = myOlApp.ActiveExplorer
Set myExplorer.CurrentFolder = myFolder
Set myRecipient = myNms.CreateRecipient("Bob the Builder")
Set SharedFolder = myNms.GetSharedDefaultFolder(myRecipient, olFolderCalendar)
myExplorer.SelectFolder SharedFolder
End Sub
If I change to 'myRecipient' part to just a name, it errors and I can't seem to work it out.
Here is something how it looks (when I do it manually) and I would like to recreate it in code.
回答1:
I think you miss the line to show the Folder selected in Outlook
myExplorer.CurrentFolder = SharedFolder
i guess instead of the "selectfolder"-line... also some of the other lines could be deleted, espacially
Set myExplorer.CurrentFolder = myFolder
as it does not make sende to open two Folders one after another in one Sub.
Yours Max
来源:https://stackoverflow.com/questions/20141659/outlook-2013-vba-display-shared-calendar