メインコンテンツへスキップ

Outlookですべての空のフォルダをバッチ削除するにはどうすればよいですか?

Outlookのメールフォルダの下に数十の空のフォルダがあると仮定します。通常、メニューを右クリックすると、空のフォルダをXNUMXつずつ削除できます。 この記事では、繰り返し右クリックするのと比較して、XNUMXつのOutlookフォルダーのすべての空のサブフォルダーをまとめてすばやく削除するVBAを紹介します。

VBAを使用してOutlookのすべての空のフォルダをバッチ削除します

Office タブ - Microsoft Office でタブによる編集と参照を有効にし、仕事をスムーズにします
Kutools for Outlook - 100 以上の高度な機能で Outlook を強化し、優れた効率を実現します
これらの高度な機能を使用して、Outlook 2021 ~ 2010 または Outlook 365 を強化します。 包括的な 60 日間の無料トライアルを利用して、メール エクスペリエンスを向上させてください。

矢印青い右バブルVBAを使用してOutlookのすべての空のフォルダをバッチ削除します

特定のOutlookフォルダーの空のサブフォルダーをすべて削除するには、次のようにします。

1。 押す 他の + F11 キーを押して、Microsoft Visual Basic forApplicationsウィンドウを開きます。

2に設定します。 OK をクリックします。 インセット > モジュール、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でフォルダ名でフォルダ(フルフォルダパス)を検索する


最高のオフィス生産性向上ツール

Outlook用Kutools - Outlook を強化する 100 以上の強力な機能

🤖 AIメールアシスタント: AI の魔法を備えたインスタント プロのメール - ワンクリックで天才的な返信、完璧な口調、多言語の習得。メールを簡単に変革しましょう! ...

📧 自動メール: 不在時 (POP および IMAP で利用可能)  /  メール送信のスケジュール設定  /  メール送信時のルールによる自動CC/BCC  /  自動転送 (高度なルール)   /  あいさつを自動追加   /  複数受信者の電子メールを個別のメッセージに自動的に分割する ...

📨 電子メール管理: メールを簡単に思い出す  /  件名などで詐欺メールをブロック  /  重複するメールを削除する  /  高度な検索  /  フォルダーを統合する ...

📁 アタッチメント プロバッチ保存  /  バッチデタッチ  /  バッチ圧縮  /  自動保存   /  自動デタッチ  /  自動圧縮 ...

🌟 インターフェースマジック: 😊もっと可愛くてクールな絵文字   /  タブ付きビューで Outlook の生産性を向上  /  Outlook を閉じる代わりに最小化する ...

???? ワンクリックの驚異: 受信した添付ファイルをすべてに返信する  /   フィッシングメール対策  /  🕘送信者のタイムゾーンを表示 ...

👩🏼‍🤝‍👩🏻 連絡先とカレンダー: 選択したメールから連絡先を一括追加  /  連絡先グループを個別のグループに分割する  /  誕生日のリマインダーを削除する ...

オーバー 100の特長 あなたの探索をお待ちしています! ここをクリックして詳細をご覧ください。

 

 

Comments (10)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
This worked great for me. Thank you. Some folders cannot be deleted as they are native to Outlook, but the sub-folders work great.
This comment was minimized by the moderator on the site
74 empty folders were deleted but unfortunately also 109 folders that were not. Other empty folders were left untouched.
This comment was minimized by the moderator on the site
Super easy and incredibly helpful. Thank you!!
This comment was minimized by the moderator on the site
I am getting the same error like Bryan.... and now?
This comment was minimized by the moderator on the site
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
This comment was minimized by the moderator on the site
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.
This comment was minimized by the moderator on the site
Agree - I get the same error.
This comment was minimized by the moderator on the site
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
This comment was minimized by the moderator on the site
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
This comment was minimized by the moderator on the site
Brilliant!!!
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations