如何输入字符串作为文件夹位置 恩。 \ MySpecificEmailAddress \收件箱 要使用Outlook在VBA中选择该文件夹? 我使用以下方式获得了路径:
... = ActiveExplorer.CurrentFolder.FolderPath
我已经远距离搜索,自动告诉脚本在哪个特定文件夹上运行宏而不必选择文件夹然后运行脚本。
答案 0 :(得分:2)
您应该能够枚举Session.Stores
,然后Store.GetRootFolder.Folders
来访问给定邮箱的所有文件夹。根据您需要多少级别,这可能需要更多的努力(即递归)。
这是code snippet from MSDN,它枚举邮箱/商店根文件夹下的所有文件夹:
Sub EnumerateFoldersInStores()
Dim colStores As Outlook.Stores
Dim oStore As Outlook.Store
Dim oRoot As Outlook.Folder
On Error Resume Next
Set colStores = Application.Session.Stores
For Each oStore In colStores
Set oRoot = oStore.GetRootFolder
Debug.Print (oRoot.FolderPath)
EnumerateFolders oRoot
Next
End Sub
Private Sub EnumerateFolders(ByVal oFolder 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
Debug.Print (Folder.FolderPath)
EnumerateFolders Folder
Next
End If
End Sub