ไปยังเนื้อหาหลัก

วิธีการแบทช์ลบโฟลเดอร์ว่างทั้งหมดใน Outlook?

สมมติว่ามีโฟลเดอร์ว่างหลายสิบโฟลเดอร์ภายใต้โฟลเดอร์เมลใน Outlook โดยทั่วไปเราสามารถลบโฟลเดอร์ว่างทีละโฟลเดอร์ได้โดยคลิกขวาที่เมนู เมื่อเทียบกับการคลิกขวาซ้ำ ๆ บทความนี้จะแนะนำ VBA เพื่อลบโฟลเดอร์ย่อยที่ว่างทั้งหมดของโฟลเดอร์ Outlook หนึ่งโฟลเดอร์จำนวนมากอย่างรวดเร็ว

Batch ลบโฟลเดอร์ว่างทั้งหมดใน Outlook ด้วย VBA

Office Tab - เปิดใช้งานการแก้ไขแบบแท็บและการเรียกดูใน Microsoft Office ทำให้งานเป็นเรื่องง่าย
Kutools for Outlook - เพิ่ม Outlook ด้วยฟีเจอร์ขั้นสูงกว่า 100+ รายการเพื่อประสิทธิภาพที่เหนือกว่า
เพิ่มประสิทธิภาพ Outlook 2021 - 2010 หรือ Outlook 365 ของคุณด้วยฟีเจอร์ขั้นสูงเหล่านี้ เพลิดเพลินกับการทดลองใช้ฟรี 60 วันและยกระดับประสบการณ์อีเมลของคุณ!

ลูกศรสีฟ้าฟองขวาBatch ลบโฟลเดอร์ว่างทั้งหมดใน Outlook ด้วย VBA

ในการลบโฟลเดอร์ย่อยว่างทั้งหมดของโฟลเดอร์ 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 สำหรับ Outlook - คุณสมบัติอันทรงพลังมากกว่า 100 รายการเพื่อเติมพลังให้กับ Outlook ของคุณ

🤖 ผู้ช่วยจดหมาย AI: ส่งอีเมลระดับมืออาชีพทันทีด้วยเวทมนตร์ AI คลิกเพียงครั้งเดียวเพื่อตอบกลับอย่างชาญฉลาด น้ำเสียงที่สมบูรณ์แบบ การเรียนรู้หลายภาษา เปลี่ยนรูปแบบการส่งอีเมลอย่างง่ายดาย! ...

📧 การทำงานอัตโนมัติของอีเมล: ไม่อยู่ที่สำนักงาน (ใช้ได้กับ POP และ IMAP)  /  กำหนดการส่งอีเมล  /  Auto 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