Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3163
  • Last Modified:

Get list of shared calendars using VBA

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
HugoMuller
Asked:
HugoMuller
  • 2
1 Solution
 
KimputerCommented:
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
 
HugoMullerAuthor Commented:
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
 
KimputerCommented:
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
 
David LeeCommented:
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now