I am tring to programmatically (with VBA) to access calendars others share with me. They are listed in my Outlook under 'People's Calendars.' I have searched the Web for this and all the suggestions have done little more than confuse me. How can I get a listing of all the calendars shared to me, and then one calendar in specific, from among the 'People's Calendars'?
3 Answers
Check out the returned values from the following code. It searches for a person by name, same way as when you are typing a recipient into a new email, and then grabs that persons shared calendar and enumerates all shared appointments.
Dim _namespace As Outlook.NameSpace
Dim _recipient As Outlook.Recipient
Dim calendarFolder As Outlook.Folder
Set _namespace = Application.GetNamespace("MAPI")
Set _recipient = _namespace.CreateRecipient(name)
_recipient.Resolve
If _recipient.Resolved Then
Set calendarFolder = _namespace.GetSharedDefaultFolder(_recipient, olFolderCalendar)
'This would display the calendar on the screen:
'calendarFolder.Display
Dim oItems As Outlook.Items
Set oItems = calendarFolder.Items
'oItems is now a set of all appointments in that person's calendar
'Play on
End if

- 26,663
- 20
- 114
- 184
-
Thanks. I always get an 'operation failed' on the 'GetSharedDefaultFolder' call. The 'name' I'm using is the person's who shared the calendar wth me. What am I overlooking? – ForEachLoop Apr 12 '11 at 15:22
-
Make sure you're passing the GetSharedDefaultFolder an Outlook.Recipient object that has resolved, not just a 'name' string. – Alain Apr 12 '11 at 16:54
-
I can't get to GetSharedDefaultFolder unless '_recipient.Resolved' was successful, correct? One observation is that in Outlook 2007, 'People's Calendars' does not show up as a Shared folder in the Folder List view. Is that a problem? – ForEachLoop Apr 12 '11 at 17:29
-
It's not a problem if you've never viewed that person's shared folder before. Only previously viewed shared folders will show up in the little outlook "People's Calendars" section. In general, any resolved contact's calendar can be opened. If they do not share their calendar, then it will simply contain no appointments, but it will still return. – Alain Apr 12 '11 at 19:11
-
The solution is working fine for me - the only thing to mention is that VBA does not like the underscore prefixes in variable names (e.g. change `_recipient` to `recipient`). After I have removed them, it was working. – Matt Feb 11 '16 at 12:13
I think this gets closer. It came from Sue Mosher's outstanding Microsoft Outlook 2007 Programming: Jumpstart for Power Users and Administrators. I hope she doesn't mind.
Sub ShowOtherUserCalFolders()
Dim objOL As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim objExpCal As Outlook.Explorer
Dim objNavMod As Outlook.CalendarModule
Dim objNavGroup As Outlook.NavigationGroup
Dim objNavFolder As Outlook.NavigationFolder
Dim objFolder As Outlook.Folder
Dim colExpl As Outlook.Explorers
Dim objExpl As Outlook.Explorer
Set objOL = Application
Set objNS = objOL.Session
Set colExpl = objOL.Explorers
Set objExpCal = _
objNS.GetDefaultFolder(olFolderCalendar).GetExplorer
Set objNavMod = objExpCal.NavigationPane.Modules. _
GetNavigationModule(olModuleCalendar)
Set objNavGroup = objNavMod.NavigationGroups. _
GetDefaultNavigationGroup(olPeopleFoldersGroup)
For Each objNavFolder In objNavGroup.NavigationFolders
Set objFolder = objNavFolder.Folder
Set objExpl = _
colExpl.Add(objFolder, olFolderDisplayNormal)
objExpl.Activate
objExpl.WindowState = olMaximized
objExpl.WindowState = olMinimized
Next
Set objOL = Nothing
Set objNS = Nothing
Set objNavMod = Nothing
Set objNavGroup = Nothing
Set objNavFolder = Nothing
Set objFolder = Nothing
Set colExpl = Nothing
Set objExpl = Nothing
End Sub

- 2,508
- 3
- 18
- 28
Just a suggestion to help people who may be trying to use the ShowOtherUserCalFolders() code posted here. This code will create multiple hidden instances of outlook which if run many times can eventual bog down your machine. Instead of creating a new Outlook.application you can call the current open one (outlook must be open for this to work).
To do this replace Dim objOL As Outlook.Application
with Dim objOL as Object
and Set objOL = Application
with Set myOlApp = GetObject(, "Outlook.Application")
Also make sure you close the objExpCal Explorer as this will also create a hidden instance of outlook, add objExpCal.Close
to the end of your code.

- 24,238
- 8
- 76
- 113

- 1
-
Since the code would be run in Outlook, the code is hooking into the existing instance of Outlook, not creating a new one. In no way would the code ForEachLoop posted create multiple instances of Outlook. Outlook is a single-instance class. See http://stackoverflow.com/questions/6481398/vba-determining-whether-an-existing-outlook-instance-is-open for further explanation. – JimmyPena Nov 21 '11 at 21:09