Solved

Get list of shared calendars using VBA

Posted on 2013-11-06
4
2,453 Views
Last Modified: 2016-02-11
I'm writing a MS-Access application which needs to import calender appointments stored in Outlook/Exchange. I'm using the outlook object and so far I am able to import my "own" appointments.

But I would like to loop over all shared calendars in my outlook and therefore I need to know the calendernames. Any suggestions how to get this "list" would be appreciated
0
Comment
Question by:HugoMuller
  • 2
4 Comments
 
LVL 35

Expert Comment

by:Kimputer
ID: 39628966
Actually, I would loop through the whole Global Address List, if the organization isn't thousands of people.
	Set GAL = myNameSpace.AddressLists("Global Address List")
	Set allGAL = GAL.AddressEntries

For i = 1 To allGAL.Count
		Set entry = allGAL.Item(i)

etc....

Open in new window


put the GetSharedDefaultFolder codevin an exception, and it will skip the ones you have no access to.
0
 

Author Comment

by:HugoMuller
ID: 39629767
Thanks for your reply.
Your solution works like a charm. This is what I made of it:
Set GAL = olNameSpace.AddressLists("Global Address List")
    Set allGAL = GAL.AddressEntries

    For i = 1 To allGAL.Count
        Set entry = allGAL.Item(i)
        On Error Resume Next
        Set calUser = olNameSpace.CreateRecipient(entry)
        Set olFolder = olNameSpace.GetSharedDefaultFolder(calUser, olFolderCalendar)
        
        'Test whether folder is a Calendar folder
        If olFolder.DefaultItemType <> olAppointmentItem Then
            Debug.Print entry & " is not accessable"
        Else
            Debug.Print entry & " is accessable"
        End If
        
    Next

Open in new window


However, this will give me list with all accessible calenders but I would like to have only the Calendars that are configured in my Outlook.

Any ideas ?
0
 
LVL 35

Accepted Solution

by:
Kimputer earned 500 total points
ID: 39629811
OK, I figured you would have configured your Outlook already with only the calendars you have access to, but I guess you actually have access to a lot of calendars you don't even want to look at.

In that case, I would debug.print all calUsers, then remove that line, and from the results, pick only the users you want, and put in an

if (calUser = user1) or (calUser = user2) or (calUser = user3) or (calUser = user4) then
    extra code of the operations you want to perform on those calendars
end if
0
 
LVL 76

Expert Comment

by:David Lee
ID: 40646857
Here's how to list all the shared calendars you have access to.  this is a modified version of some sample code from Sue Mosher's book "Microsoft Outlook 2007 Programming: Jumpstart for Power Users and Administrators".

Sub ListSharedCalendars()
    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
    Set objExpCal = Session.GetDefaultFolder(olFolderCalendar).GetExplorer
    Set objNavMod = objExpCal.NavigationPane.Modules.GetNavigationModule(olModuleCalendar)
    Set objNavGroup = objNavMod.NavigationGroups.GetDefaultNavigationGroup(olPeopleFoldersGroup)
    For Each objNavFolder In objNavGroup.NavigationFolders
        Debug.Print objNavFolder.DisplayName
    Next
    Set objNavMod = Nothing
    Set objNavGroup = Nothing
    Set objNavFolder = Nothing
    Set objFolder = Nothing
End Sub

Open in new window

0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you unable to connect or configure Hotmail email account in Microsoft Outlook 2010, 2007? Or Outlook.com emails are not downloading to Outlook? Lets’ see the problem and resolve Outlook Connector error syncing folder hierarchy (0x8004102A).
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question