提示:其他語言是Google翻譯的。 你可以訪問 English 版本。
登入
x
or
x
x
註冊
x

or

如何批量刪除Outlook中的所有空文件夾?

假設Outlook中的郵件文件夾下有幾十個空文件夾,通常我們可以通過右鍵菜單逐個刪除空文件夾。 與重複右鍵單擊相比,本文將介紹VBA以批量快速刪除一個Outlook文件夾的所有空子文件夾。

使用VBA批量刪除Outlook中的所有空文件夾

Office選項卡 - 在Office中啟用選項卡式編輯和瀏覽,使工作更輕鬆......
Kutools for Outlook - 為Microsoft Outlook帶來100強大的高級功能
  • 自動CC / BCC 發送電子郵件時的規則; 自動轉發 規則多個電子郵件; 自動回复 沒有交換服務器,以及更多自動功能......
  • BCC警告 - 如果您的郵件地址在BCC列表中,當您嘗試全部回复時顯示消息; 缺少附件時提醒,以及更多提醒功能......
  • 全部附件回复(全部) 在郵件對話中; 立即回复許多電子郵件; 自動添加問候語 回复時; 自動將日期和時間添加到主題中...
  • 附件工具:自動分離,全部壓縮,全部重命名,自動全部保存... 快速報告,計算選定的郵件, 刪除重複的郵件和聯繫人...
  • 超過100高級功能將 解決你的大多數問題 在Outlook 2010-2019和365中。 全功能60天免費試用。

箭頭藍色右泡使用VBA批量刪除Outlook中的所有空文件夾

要刪除某個Outlook文件夾的所有空子文件夾,請執行以下操作:

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

2。 點擊 插入 > 模塊,並將VBA代碼粘貼到新的模塊窗口中。

VBA:批量刪除某些Outlook文件夾的所有空子文件夾

Public Sub DeletindEmtpyFolder()
Dim xFolders As Folders
Dim xCount As Long
Dim xFlag As Boolean
Set xFolders = Application.GetNamespace("MAPI").PickFolder.Folders
Do
FolderPurge xFolders, xFlag, xCount
Loop Until (Not xFlag)
If xCount > 0 Then
MsgBox "Deleted " & xCount & "(s) empty folders", vbExclamation + vbOKOnly, "Kutools for Outlook"
Else
MsgBox "No empty folders found", vbExclamation + vbOKOnly, "Kutools for Outlook"
End If
End Sub

Public Sub FolderPurge(xFolders, xFlag, xCount)
Dim I As Long
Dim xFldr As Folder 'Declare sub folder objects
xFlag = False
If xFolders.Count > 0 Then
For I = xFolders.Count To 1 Step -1
Set xFldr = xFolders.Item(I)
If xFldr.Items.Count < 1 Then 'If the folder is empty check for subfolders
If xFldr.Folders.Count < 1 Then 'If the folder contains not sub folders confirm deletion
xFldr.Delete 'Delete the folder
xFlag = True
xCount = xCount + 1
Else 'Folder contains sub folders so confirm deletion
FolderPurge xFldr.Folders, xFlag, xCount
End If
Else 'Folder contains items or (subfolders that may be empty).
FolderPurge xFldr.Folders, xFlag, xCount
End If
Next
End If
End Sub

3。 按 F5 鍵或 按鈕來運行這個VBA代碼。

4。 在彈出的選擇文件夾對話框中,請選擇您要批量刪除空子文件夾的特定文件夾,然後單擊 OK 按鈕。 看截圖:

5。 現在出現一個Kutools for Outlook對話框,並顯示已刪除多少個空子文件夾。 點擊 OK 按鈕關閉它。

到目前為止,指定的Outlook文件夾的所有子文件夾已被批量刪除。


箭頭藍色右泡相關文章

在Outlook中按文件夾名稱查找文件夾(完整文件夾路徑)


Kutools for Outlook - 為Outlook帶來100高級功能,讓工作更輕鬆!

  • 自動CC / BCC 發送電子郵件時的規則; 自動轉發 多個電子郵件按自定義; 自動回复 沒有交換服務器,以及更多自動功能......
  • BCC警告 - 當您嘗試回复所有內容時顯示消息 如果您的郵件地址在BCC列表中; 缺少附件時提醒,以及更多提醒功能......
  • 回复(全部)使用郵件會話中的所有附件; 回复很多電子郵件 很快; 自動添加問候語 回复時; 將日期添加到主題...
  • 附件工具:管理所有郵件中的所有附件, 自動分離, 全部壓縮,重命名全部,全部保存...快速報告, 計算選定的郵件...
  • 強大的垃圾郵件 按慣例; 刪除重複郵件和聯繫人... 使您能夠在Outlook中更智能,更快速,更好地完成工作。
拍攝kutools outlook kutools選項卡1180x121
拍攝kutools outlook kutools加標籤1180x121
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Martin · 5 months ago
    74 empty folders were deleted but unfortunately also 109 folders that were not. Other empty folders were left untouched.
  • To post as a guest, your comment is unpublished.
    Adam · 1 years ago
    Super easy and incredibly helpful. Thank you!!
  • To post as a guest, your comment is unpublished.
    Spooz · 1 years ago
    I am getting the same error like Bryan.... and now?
    • To post as a guest, your comment is unpublished.
      Carina · 8 months ago
      The script tries to delete a folder that was already deleted.
      I added a row after xFlag = False with this content:
      on error resume next
  • To post as a guest, your comment is unpublished.
    Bryan · 1 years ago
    I am getting the following error when run the above " Run-time error '-2147352567 (80020009)' Cannot delete this folder. Right-click the folder, and then click properties to check your permissions for the folder. See the folder owner or your administrator to change your permissions"

    It appears the script moves 1 item to the deleted folder and then errors out.
    • To post as a guest, your comment is unpublished.
      TechGiant · 1 years ago
      Agree - I get the same error.
      • To post as a guest, your comment is unpublished.
        Carina · 8 months ago
        The script tries to delete a folder that was already deleted.
        I added a row after xFlag = False with this content:
        on error resume next
        • To post as a guest, your comment is unpublished.
          Munier Saliba · 8 months ago
          Indeed, add:

          On Error Resume Next

          AFTER:

          Dim x Fldr As Folder 'Declare sub folder objects
          xFlag = False

          It should look like this:

          Dim x Fldr As Folder 'Declare sub folder objects
          xFlag = False
          On Error Resume Next
  • To post as a guest, your comment is unpublished.
    Miroslav · 1 years ago
    Brilliant!!!