使用文件夹路径字符串在Outlook中的VBA中选择文件夹 [英] Use Folder Path String to select folder in VBA in Outlook
问题描述
如何输入字符串作为文件夹位置 前任. \ MySpecificEmailAddress \ Inbox 要使用Outlook在VBA中选择该文件夹? 我使用以下方式获取了路径:
How can I enter a string as a folder location ex. \MySpecificEmailAddress\Inbox To select that folder in VBA using outlook? I obtained the path using:
... = ActiveExplorer.CurrentFolder.FolderPath
我进行了广泛搜索,以自动告诉脚本在哪个特定文件夹上运行宏,而不必选择该文件夹然后运行脚本.
I have searched far and wide to automatically tell the script which specific folder to run a macro on without having to select the folder then run the script.
推荐答案
您应该能够枚举 Session.Stores
,然后
You should be able to enumerate Session.Stores
and then Store.GetRootFolder.Folders
to access all folders for a given mailbox. Depending on how many levels deep you need to go, this may take a bit more effort (i.e. recursion).
这是一个来自MSDN的代码段,其中列举了所有邮箱/存储根文件夹下的文件夹:
Here is a code snippet from MSDN which enumerates all folders under the mailbox/store root folders:
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
这篇关于使用文件夹路径字符串在Outlook中的VBA中选择文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!