VBA, Outlook, Seeing 'People's Calendars

前端 未结 3 1486
野趣味
野趣味 2020-12-18 11:37

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

相关标签:
3条回答
  • 2020-12-18 12:15

    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
    
    0 讨论(0)
  • 2020-12-18 12:24

    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
    
    0 讨论(0)
  • 2020-12-18 12:29

    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.

    0 讨论(0)
提交回复
热议问题