跳到主要内容

如何从Outlook中打开所有子文件夹?

作者:晓阳 最后修改时间:2018-11-21

如果在Outlook文件夹下创建多个子文件夹,如何立即打开或展开所有这些子文件夹? 本文,我将为您介绍一个有用的VBA代码,以解决该工作。

使用VBA代码从Outlook中打开或展开所有子文件夹


使用VBA代码从Outlook中打开或展开所有子文件夹

请应用以下VBA代码以扩展所有Outlook帐户的所有子文件夹:

1。 按住 ALT + F11 键打开 Microsoft Visual Basic应用程序 窗口。

2。 点击 插页 > 模块,然后将以下宏粘贴到“模块窗口”中。

VBA代码:从Outlook中打开所有子文件夹:

Sub ExpandAllMailFolders()
    Dim xCurrentFolder As Folder
    Dim xAllFolders As Folders
    Dim xFolder As Folder
    On Error Resume Next
    Set xCurrentFolder = Application.ActiveExplorer.CurrentFolder
    Set xAllFolders = Application.Session.Folders
    For Each xFolder In xAllFolders
        Call ProcessFolders(xFolder)
    Next
    Set Application.ActiveExplorer.CurrentFolder = xCurrentFolder
End Sub
Sub ProcessFolders(ByVal CurFolder As Folder)
    Dim xSubfolder As Folder
    On Error Resume Next
    If CurFolder.DefaultItemType <> olMailItem Then Exit Sub
    Set Application.ActiveExplorer.CurrentFolder = CurFolder
    DoEvents
    If CurFolder.Folders.Count = 0 Then Exit Sub
    For Each xSubfolder In CurFolder.Folders
        Call ProcessFolders(xSubfolder)
    Next
End Sub

3。 然后按 F5 键来运行此代码,并且Outlook的所有帐户中的所有子文件夹都已扩展,请参见屏幕截图:

doc扩展子文件夹1


最佳办公生产力工具

最新消息:Kutools for Outlook 发布 免费版本!

体验全新的 Kutools for Outlook 免费版本拥有 70 多项令人难以置信的功能,您可以永久使用! 点击立即下载!

🤖 Kutools人工智能 : 具有人工智能魔力的即时专业电子邮件——一键天才回复、完美语气、多语言掌握。轻松改变电子邮件! ...

📧 电子邮件自动化: 自动回复(适用于 POP 和 IMAP)  /  安排发送电子邮件  /  发送电子邮件时按规则自动抄送/密件抄送  /  自动转发(高级规则)   /  自动添加问候语   /  自动将多收件人电子邮件拆分为单独的消息 ...

📨 电子邮件管理: 撤回电子邮件  /  按主题和其他人阻止诈骗电子邮件  /  删除重复的电子邮件  /  高级搜索  /  合并文件夹 ...

📁 附件专业版批量保存  /  批量分离  /  批量压缩  /  自动保存   /  自动分离  /  自动压缩 ...

🌟 界面魔法: 😊更多又漂亮又酷的表情符号   /  收到重要邮件时提醒您  /  最小化 Outlook 而不是关闭 ...

👍 一键奇迹: 使用传入附件回复全部  /   反网络钓鱼电子邮件  /  🕘显示发件人的时区 ...

👩🏼‍🤝‍👩🏻 通讯录和日历: 从选定的电子邮件中批量添加联系人  /  将联系人组拆分为各个组  /  删除生日提醒 ...

只需单击一下即可立即解锁 Kutools for Outlook -永久免费. 别等了, 立即下载并提高您的效率!

kutools for outlook 功能1 kutools for outlook 功能2
 

 

 

Comments (3)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Guten Abend,

habe das o.g. Makro ausgetestet und es funktioniert super, ABER...

könnte man auch sagen öffne nur die Unterordner eines bestimmten Hauptordners?
Wenn ja, wie?

Vielen Dank!
This comment was minimized by the moderator on the site
Hello, Sandra,
To only open the subfolders from a specific folder, please apply the below code:
Sub ExpandAllMailFolders()
    Dim xCurrentFolder As Folder
    Dim xFolder As Folder
    On Error Resume Next
    Set xCurrentFolder = Application.ActiveExplorer.CurrentFolder
    Set xFolder = Application.Session.PickFolder
    If xFolder Is Nothing Then Exit Sub
    Call ProcessFolders(xFolder)
    Set Application.ActiveExplorer.CurrentFolder = xCurrentFolder
End Sub
Sub ProcessFolders(ByVal CurFolder As Folder)
    Dim xSubfolder As Folder
    On Error Resume Next
    If CurFolder.DefaultItemType <> olMailItem Then Exit Sub
    Set Application.ActiveExplorer.CurrentFolder = CurFolder
    DoEvents
    If CurFolder.Folders.Count = 0 Then Exit Sub
    For Each xSubfolder In CurFolder.Folders
        Call ProcessFolders(xSubfolder)
    Next
End Sub

Please try, hope it can help you!
This comment was minimized by the moderator on the site
I have been looking for this answer for a long time! Thank you.
There are no comments posted here yet
Leave your comments
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations