如何導出和打印Outlook中所有文件夾和子文件夾的列表?
一般來說,您可以按 按Ctrl + 6 鍵以查看Outlook導航窗格中所有文件夾的列表。 但是,您無法打印文件夾列表。 本文將介紹兩個VBA腳本,以導出和打印Outlook中所有文件夾及其子文件夾的列表。
在新電子郵件中導出並打印所有Outlook文件夾及其子文件夾的列表
此方法將引入VBA,以將指定電子郵件帳戶中的所有文件夾及其子文件夾的列表導出到Outlook中的新電子郵件中,然後您可以輕鬆地打印文件夾列表。
1。 按 其他 + F11 鍵以打開“ Microsoft Visual Basic應用程序”窗口。
2。 點擊 插入 > 模塊,然後將以下VBA代碼粘貼到新的“模塊”窗口中。
VBA:在Outlook中的新電子郵件中導出文件夾和子文件夾的列表
Public gFolders As String
Public Sub GetFolderNames()
Dim oSession As Outlook.NameSpace
Dim oFolder As Outlook.MAPIFolder
Dim oNewMail As Outlook.mailItem
Set oSession = Outlook.Application.GetNamespace("MAPI")
Set oFolder = oSession.PickFolder
If (oFolder Is Nothing) Then Exit Sub
ProcessFolder oFolder
Set oNewMail = Application.CreateItem(olMailItem)
oNewMail.Body = gFolders
oNewMail.Display
gFolders = ""
End Sub
Sub ProcessFolder(CurrentFolder As Outlook.MAPIFolder)
Dim i As Long
Dim oSubFolder As Outlook.MAPIFolder
Dim oFolder As Outlook.MAPIFolder
Dim sFolderPaths As String
For i = CurrentFolder.Folders.Count To 1 Step -1
Set oFolder = CurrentFolder.Folders(i)
sFolderPaths = oFolder.FolderPath
gFolders = gFolders & vbCrLf & sFolderPaths & " " & oFolder.Items.Count
Next
For Each oSubFolder In CurrentFolder.Folders
If oSubFolder.Name <> "Deleted Items" Then
ProcessFolder oSubFolder
End If
Next
End Sub
3。 按 F5 運行此VBA的關鍵。
4.在彈出的選擇文件夾對話框中,選擇您要打印其文件夾列表的電子郵件帳戶,然後單擊 OK 按鈕。 看截圖:
5.現在,將指定電子郵件帳戶的文件夾列表複製到新電子郵件中,如下圖所示。 請點擊 文件 > 列印 打印文件夾的複制列表。
6.打印後,請關閉新的電子郵件而不保存。
在記事本中導出並打印所有Outlook文件夾及其子文件夾的列表
此方法將引入VBA,以將指定電子郵件帳戶中的所有文件夾及其子文件夾的列表從Outlook導出到記事本,然後您可以輕鬆地在記事本中打印Outlook文件夾的列表。
1。 按 其他 + F11 鍵以打開“ Microsoft Visual Basic應用程序”窗口。
2。 點擊 插入 > 模塊,然後將以下VBA代碼粘貼到新的“模塊”窗口中。
VBA:將所有Outlook文件夾和子文件夾的列表從Outlook導出到記事本
Dim gFileName, gCreateTree, gBase
Public Sub ExportFolderTree()
Dim objOutlook
Dim F, Folders
Dim Result
Set objOutlook = CreateObject("Outlook.Application")
Set F = objOutlook.Session.PickFolder
If Not F Is Nothing Then
Set Folders = F.Folders
Result = MsgBox("Do you want to create tree?", vbYesNo + vbDefaultButton2 + vbApplicationModal, "Output Folder Tree")
If Result = 6 Then
gCreateTree = True
Else
gCreateTree = False
End If
gFileName = GetDesktopFolder() & "\Outlook-Folders.txt"
gBase = Len(F.FolderPath) - Len(Replace(F.FolderPath, "\", "")) + 1
WriteToATextFile (CreateFolderTree(F.FolderPath, F.Name))
LoopFolders Folders
Set F = Nothing
Set Folders = Nothing
Set objOutlook = Nothing
End If
End Sub
Private Function GetDesktopFolder()
Dim objShell
Set objShell = CreateObject("WScript.Shell")
GetDesktopFolder = objShell.SpecialFolders("Desktop")
Set objShell = Nothing
End Function
Private Sub LoopFolders(Folders)
Dim F
For Each F In Folders
WriteToATextFile (CreateFolderTree(F.FolderPath, F.Name))
LoopFolders F.Folders
Next
End Sub
Private Sub WriteToATextFile(OLKfoldername)
Dim objFSO, objTextFile
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(gFileName, 8, True)
objTextFile.WriteLine (OLKfoldername)
objTextFile.Close
Set objFSO = Nothing
Set objTextFile = Nothing
End Sub
Private Function CreateFolderTree(OLKfolderpath, OLKfoldername)
If gCreateTree = False Then
CreateFolderTree = Mid(OLKfolderpath, 3)
Else
Dim i, x, OLKprefix
i = Len(OLKfolderpath) - Len(Replace(OLKfolderpath, "\", ""))
For x = gBase To i
OLKprefix = OLKprefix & "-"
Next
CreateFolderTree = OLKprefix & OLKfoldername
End If
End Function
3。 按 F5 運行此VBA的關鍵。 在打開的“選擇文件夾”對話框中,接下來,請選擇要導出和打印其文件夾列表的電子郵件帳戶,然後單擊 OK 按鈕。 看截圖:
4.然後出現“輸出文件夾樹”對話框。 請點擊 是 按鈕或 沒有 按鈕,根據需要。
現在一個名為的文本文件 展望文件夾 創建並保存在您的桌面上,如下圖所示。
5.雙擊打開新的文本文件,然後單擊 文件 > 列印 打印Outlook文件夾的導出列表。
一鍵式顯示Outlook導航窗格上所有文件夾中的項目總數
通常,Outlook在導航窗格上的每個文件夾中顯示未讀項目的數量。 但是,Kutools for Outlook的 所有文件夾顯示項目總數 功能可以幫助您一鍵顯示所有文件夾中的項目總數。

相關文章
Kutools for Outlook-為Outlook帶來100個高級功能,並使工作更加輕鬆!
- 自動CC / BCC 根據規則發送電子郵件; 自動前進 自定義多封電子郵件; 自動回复 沒有交換服務器,還有更多自動功能...
- BCC警告 -當您嘗試全部答复時顯示消息 如果您的郵件地址在“密件抄送”列表中; 缺少附件時提醒,還有更多提醒功能...
- 在郵件對話中回复(全部)帶有所有附件; 回复許多電子郵件 片刻之間; 自動添加問候語 回复時將日期添加到主題中...
- 附件工具:管理所有郵件中的所有附件, 自動分離, 全部壓縮,重命名全部,保存全部...快速報告, 計算選定的郵件...
- 強大的垃圾郵件 習俗 刪除重複的郵件和聯繫人... 使您能夠在Outlook中做得更聰明,更快和更好。

