跳到主要內容

如何在Outlook中獲取文件夾列表?

有時,導航窗格中所有郵件文件夾(包括創建的個人文件夾)的樹結構可以為Outlook用戶在工作期間提供一些幫助。 為了快速列出整個樹結構文件夾,VBA代碼可以為您提供幫助。 在本教程中,您可以學習如何使用VBA代碼輕鬆獲取文件夾列表。

使用VBA代碼獲取Outlook中的文件夾列表

Office 標籤 - 在 Microsoft Office 中啟用選項卡式編輯和瀏覽,讓工作變得輕而易舉
Kutools for Outlook - 透過 100 多個進階功能增強 Outlook,實現卓越效率
使用這些進階功能增強您的 Outlook 2021 - 2010 或 Outlook 365。 享受全面的 60 天免費試用並提升您的電子郵件體驗!

箭頭藍色右氣泡使用VBA代碼獲取Outlook中的文件夾列表

要獲取帶有VBA代碼的Outlook中的文件夾列表,請執行以下操作。

1。 按 其他 + F11 鍵盤上的按鍵打開 Microsoft Visual Basic for Applications 窗口。

2.然後雙擊 Project1 > Microsoft Outlook對象 > 本次展望會議 打開 項目1 – ThisOutlookSession 窗口。 看截圖:

3.然後將下面的VBA代碼複製並粘貼到Project1 – ThisOutlookSession窗口中。

VBA:獲取Outlook中的文件夾列表

Option Explicit
Sub GetFoldersList()
    On Error GoTo On_Error
    
    Dim Report As String
    Dim Folder As Outlook.Folder
       
    For Each Folder In Application.Session.Folders
        Report = Report & "---------------------------------------------------------------------------" & vbCrLf
        Call RecurseFolders(Folder, "", Report)
    Next
    Call CreateReportEmail("Outlook Folders List", Report)
    
Exiting:
    Exit Sub
On_Error:
    MsgBox "error=" & Err.Number & " " & Err.Description
End Sub
Sub RecurseFolders(CurrentFolder As Outlook.Folder, TabChars, ByRef Report As String)
    Dim SubFolder As Outlook.Folder
    Dim FolderName, StoreName As String
    
    FolderName = CurrentFolder.Name
    StoreName = CurrentFolder.Store.DisplayName
    
    Report = Report & TabChars & FolderName & " (Store: " & StoreName & ")" & vbCrLf
    
    For Each SubFolder In CurrentFolder.Folders
        Call RecurseFolders(SubFolder, TabChars & vbTab, Report)
    Next SubFolder
End Sub
Sub CreateReportEmail(Title As String, Report As String)
    Dim aMail As MailItem
    
    Set aMail = Application.CreateItem(olMailItem)
        
    aMail.Subject = Title
    aMail.Body = Report
    
    aMail.Display
End Sub

4。 按 F5 鍵盤上的鍵開始運行VBA代碼。

5.現在一個 彈出對話框,請點擊 按鈕。

6.等待宏運行。 然後,所有電子郵件文件夾的列表會立即在創建的新消息窗口中列出。 您可以輕鬆地將其打印出來。 看截圖:

備註:此VBA代碼可以應用於Outlook 2007、2010和2013。


最佳辦公生產力工具

Kutools for Outlook - 超過 100 種強大的功能可增強您的 Outlook

🤖 人工智慧郵件助手: 具備人工智慧魔力的即時專業電子郵件——一鍵天才回覆、完美語調、多語言掌握。輕鬆改變電子郵件! ……

📧 電子郵件自動化: 外出(適用於 POP 和 IMAP)  /  安排發送電子郵件  /  發送電子郵件時按規則自動抄送/密件副本  /  自動轉送(進階規則)   /  自動添加問候語   /  自動將多收件者電子郵件拆分為單獨的訊息 ...

📨 電子郵件管理: 輕鬆回憶電子郵件  /  按主題和其他人阻止詐騙電子郵件  /  刪除重複的電子郵件  /  進階搜索  /  合併資料夾 ...

📁 附件專業版批量保存  /  批量分離  /  批量壓縮  /  自動保存   /  自動分離  /  自動壓縮 ...

🌟 介面魔法: 😊更多又漂亮又酷的表情符號   /  使用選項卡式視圖提高 Outlook 工作效率  /  最小化 Outlook 而不是關閉 ...

👍 一鍵奇蹟: 使用傳入附件回覆全部  /   反網路釣魚電子郵件  /  🕘顯示寄件者的時區 ...

👩🏼‍🤝‍👩🏻 通訊錄和行事曆: 從選定的電子郵件中大量新增聯絡人  /  將聯絡人群組拆分為各組  /  刪除生日提醒 ...

超過 100特點 等待您的探索! 按此處了解更多。

閱讀更多       免費下載      購買
 

 

Comments (2)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
For get the size of the folders how do you do it?
This comment was minimized by the moderator on the site
Working perfect with OLK 365, Thank you!
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations