枚举所有存储区上的文件夹
本主题显示一个代码示例,该示例枚举会话的所有存储区上的所有文件夹。
代码示例首先使用当前会话的 NameSpace.Stores 属性获取当前会话
Application.Session
的所有存储。对于此会话的每个存储区,该示例使用 Store.GetRootFolder 获取存储区根目录文件夹。
对于每个存储的根文件夹,它会以迭代方式调用过程,
EnumerateFolders
直到它访问并显示该树中每个文件夹的名称。
备注
要运行此代码示例,请将代码放置在内置 ThisOutlookSession 模块中。 运行 EnumerateFoldersInStores
过程:
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
支持和反馈
有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。