Outlook VBA使用公用存储文件夹

问题描述 投票:0回答:1

我正在尝试将事件添加到公共商店中的Outlook日历(例如,不属于任何特定用户的PF商店)

如何引用该文件夹(日历)以便能够处理其中的项目?

通过路径枚举(以及下面的代码)大约需要两分钟才能在我想要的文件夹下工作,然后我无法在原始子例程中设置对它的引用。

枚举改编自MSDN here

Public Function EnumerateFoldersInStores(ByVal searchFolder As String) As Outlook.Folder
    Dim colStores As Outlook.Stores
    Dim oStore As Outlook.Store
    Dim oRoot As Outlook.Folder

    On Error Resume Next
    Set EnumerateFoldersInStores = Nothing
    Set colStores = Application.Session.Stores

    For Each oStore In colStores
        Set oRoot = oStore.GetRootFolder

        If oRoot.Name = searchFolder Then
            Debug.Print (oRoot.FolderPath)
            Set EnumerateFoldersInStores = EnumerateFolders(oRoot)
        End If
    Next
End Function

Private Function EnumerateFolders(ByVal oFolder As Outlook.Folder) As Outlook.Folder
    Dim folders As Outlook.folders
    Dim Folder As Outlook.Folder
    Dim foldercount As Integer

    On Error Resume Next

    Set folders = oFolder.folders
    foldercount = folders.Count

    'Check if there are any folders below oFolder
    If foldercount Then
        For Each Folder In folders
            Select Case Folder.Name
            Case "All Public Folders"
                Debug.Print (Folder.FolderPath)
                EnumerateFolders Folder
            Case "Sub-Location"
                Debug.Print (Folder.FolderPath)
                EnumerateFolders Folder
            Case "Department"
                Debug.Print (Folder.FolderPath)
                EnumerateFolders Folder
            Case "Division"
                Debug.Print (Folder.FolderPath)
                EnumerateFolders Folder
            Case "Work-Group"
                Debug.Print (Folder.FolderPath)
                EnumerateFolders Folder
            Case "Planning-Calendar"
                ' This is the folder I want to work with
                Debug.Print (Folder.FolderPath)
                Stop
                Set EnumerateFolders = Folder
            End Select
        Next
    End If
End Function

完整的路径是:\\Public Folders - [email protected]\All Public Folders\Sub-Location\Department\Division\Work-Group\Planning-Calendar

vba outlook enumeration shared-directory
1个回答
1
投票

引用公用文件夹:\ Public Folders - [email protected] \ All Public Folders \ Sub-Location \ Department \ Division \ Work-Group \ Planning-Calendar

Set PbFldr = GetNamespace("MAPI").GetDefaultFolder(olPublicFoldersAllPublicFolders)
Set PbFldr = PbFldr.Folders("Sub-Location")
Set PbFldr = PbFldr.Folders("Department")
Set PbFldr = PbFldr.Folders("Division")
Set PbFldr = PbFldr.Folders("Work-Group")
Set PbFldr = PbFldr.Folders("Planning-Calendar")
© www.soinside.com 2019 - 2024. All rights reserved.