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

จะย้ายอีเมลไปยังโฟลเดอร์ที่ระบุหลังจากกำหนดหมวดหมู่ใน Outlook ได้อย่างไร

สมมติว่าคุณกำหนดหมวดหมู่ให้กับอีเมลที่ได้รับใน Outlook ของคุณหลังจากกำหนดประเภทแล้วคุณต้องการให้อีเมลนี้ย้ายไปยังโฟลเดอร์อีเมลที่มีชื่อหมวดหมู่โดยอัตโนมัติ ตัวอย่างเช่นอีเมลที่กำหนดหมวดหมู่ "ส่วนตัว" จะถูกย้ายไปยังชื่อโฟลเดอร์ "ส่วนตัว" ใน Outlook ของคุณ จะบรรลุได้อย่างไร? วิธีการในบทความนี้สามารถช่วยคุณแก้ปัญหาได้อย่างง่ายดาย

ย้ายอีเมลไปยังโฟลเดอร์ที่ระบุหลังจากกำหนดหมวดหมู่บางประเภทด้วย VBA


ย้ายอีเมลไปยังโฟลเดอร์ที่ระบุหลังจากกำหนดหมวดหมู่บางประเภทด้วย VBA

รหัส VBA ด้านล่างสามารถช่วยในการย้ายอีเมลไปยังโฟลเดอร์ที่ระบุโดยอัตโนมัติหลังจากกำหนดหมวดหมู่บางหมวดใน Outlook กรุณาดำเนินการดังนี้

1 กด อื่น ๆ + F11 คีย์เพื่อเปิด Microsoft Visual Basic สำหรับแอปพลิเคชัน หน้าต่าง

2 ใน Microsoft Visual Basic สำหรับแอปพลิเคชัน ดับเบิลคลิกเพื่อเปิดไฟล์ ThisOutlookSession (รหัส) หน้าต่าง. จากนั้นคัดลอกโค้ด VBA ด้านล่างลงในหน้าต่าง ดูภาพหน้าจอ:

รหัส VBA: ย้ายอีเมลไปยังโฟลเดอร์ที่ระบุหลังจากกำหนดหมวดหมู่บางประเภท

Private WithEvents xInboxFld As Outlook.Folder
Private WithEvents xInboxItems As Outlook.Items

Private Sub Application_Startup()
    Set xInboxFld = Outlook.Application.Session.GetDefaultFolder(olFolderInbox)
    Set xInboxItems = xInboxFld.Items
End Sub

Private Sub xInboxItems_ItemChange(ByVal Item As Object)
Dim xMailItem As Outlook.MailItem
Dim xFlds As Outlook.Folders
Dim xFld As Outlook.Folder
Dim xTargetFld As Outlook.Folder
Dim xFlag As Boolean
On Error Resume Next
If Item.Class = olMail Then
    Set xMailItem = Item
    xFlag = False
    If xMailItem.Categories <> "" Then
        Set xFlds = Application.Session.GetDefaultFolder(olFolderInbox).Folders
        If xFlds.Count <> 0 Then
            For Each xFld In xFlds
                If xFld.Name = xMailItem.Categories Then
                    xFlag = True
                End If
            Next
        End If
        If xFlag = False Then
            Application.Session.GetDefaultFolder(olFolderInbox).Folders.Add xMailItem.Categories, olFolderInbox
        End If
        Set xTargetFld = Application.Session.GetDefaultFolder(olFolderInbox).Folders(xMailItem.Categories)
        xMailItem.Move xTargetFld
    End If
End If
End Sub

3. บันทึกรหัสและรีสตาร์ท Outlook

4. จากนี้ไป เมื่อกำหนดหมวดหมู่ให้กับอีเมลที่ได้รับ โฟลเดอร์ที่มีชื่อหมวดหมู่จะถูกสร้างขึ้นโดยอัตโนมัติภายใต้โฟลเดอร์กล่องขาเข้าพร้อมกับอีเมลที่ย้ายเข้ามา ดูภาพหน้าจอ:

หมายเหตุ: อีเมลทั้งหมดที่กำหนดหมวดหมู่เดียวกันจะถูกย้ายไปยังโฟลเดอร์เดียวกันโดยอัตโนมัติ แต่หากมีการกำหนดหมวดหมู่ใหม่ให้กับอีเมล โฟลเดอร์ใหม่จะถูกสร้างขึ้นโดยอัตโนมัติ


บทความที่เกี่ยวข้อง:

สุดยอดเครื่องมือเพิ่มผลผลิตในสำนักงาน

🤖 Kutools AI ผู้ช่วย: ปฏิวัติการวิเคราะห์ข้อมูลโดยยึดตาม: การดำเนินการที่ชาญฉลาด   |  สร้างรหัส  |  สร้างสูตรที่กำหนดเอง  |  วิเคราะห์ข้อมูลและสร้างแผนภูมิ  |  เรียกใช้ฟังก์ชัน Kutools...
คุณสมบัติยอดนิยม: ค้นหา เน้น หรือระบุรายการที่ซ้ำกัน   |  ลบแถวว่าง   |  รวมคอลัมน์หรือเซลล์โดยไม่สูญเสียข้อมูล   |   รอบโดยไม่มีสูตร ...
การค้นหาขั้นสูง: VLookup หลายเกณฑ์    VLookup หลายค่า  |   VLookup ข้ามหลายแผ่น   |   การค้นหาที่ไม่ชัดเจน ....
รายการแบบเลื่อนลงขั้นสูง: สร้างรายการแบบหล่นลงอย่างรวดเร็ว   |  รายการแบบหล่นลงขึ้นอยู่กับ   |  เลือกหลายรายการแบบหล่นลง ....
ผู้จัดการคอลัมน์: เพิ่มจำนวนคอลัมน์เฉพาะ  |  ย้ายคอลัมน์  |  สลับสถานะการมองเห็นของคอลัมน์ที่ซ่อนอยู่  |  เปรียบเทียบช่วงและคอลัมน์ ...
คุณสมบัติเด่น: กริดโฟกัส   |  มุมมองการออกแบบ   |   บาร์สูตรใหญ่    สมุดงานและตัวจัดการชีต   |  ห้องสมุดทรัพยากร (ข้อความอัตโนมัติ)   |  เลือกวันที่   |  รวมแผ่นงาน   |  เข้ารหัส/ถอดรหัสเซลล์    ส่งอีเมลตามรายการ   |  ซุปเปอร์ฟิลเตอร์   |   ตัวกรองพิเศษ (กรองตัวหนา/ตัวเอียง/ขีดทับ...) ...
ชุดเครื่องมือ 15 อันดับแรก12 ข้อความ เครื่องมือ (เพิ่มข้อความ, ลบอักขระ, ... )   |   50 + แผนภูมิ ประเภท (แผนภูมิ Gantt, ... )   |   40+ ใช้งานได้จริง สูตร (คำนวณอายุตามวันเกิด, ... )   |   19 การแทรก เครื่องมือ (ใส่ QR Code, แทรกรูปภาพจากเส้นทาง, ... )   |   12 การแปลง เครื่องมือ (ตัวเลขเป็นคำ, การแปลงสกุลเงิน, ... )   |   7 ผสานและแยก เครื่องมือ (แถวรวมขั้นสูง, แยกเซลล์, ... )   |   ... และอื่น ๆ

เพิ่มพูนทักษะ Excel ของคุณด้วย Kutools สำหรับ Excel และสัมผัสประสิทธิภาพอย่างที่ไม่เคยมีมาก่อน Kutools สำหรับ Excel เสนอคุณสมบัติขั้นสูงมากกว่า 300 รายการเพื่อเพิ่มประสิทธิภาพและประหยัดเวลา  คลิกที่นี่เพื่อรับคุณสมบัติที่คุณต้องการมากที่สุด...

รายละเอียด


แท็บ Office นำอินเทอร์เฟซแบบแท็บมาที่ Office และทำให้งานของคุณง่ายขึ้นมาก

  • เปิดใช้งานการแก้ไขและอ่านแบบแท็บใน Word, Excel, PowerPoint, ผู้จัดพิมพ์, Access, Visio และโครงการ
  • เปิดและสร้างเอกสารหลายรายการในแท็บใหม่ของหน้าต่างเดียวกันแทนที่จะเป็นในหน้าต่างใหม่
  • เพิ่มประสิทธิภาพการทำงานของคุณ 50% และลดการคลิกเมาส์หลายร้อยครั้งให้คุณทุกวัน!
Comments (8)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Bonjour
je cherchais cette fonction depuis un moment pour classer mes mails.
Malheureusement ça ne fonctionne pas. J'ai outlook 2019 au boulot peut-être est-ce à cause de ça ? ou alors vu que je ne maitrise pas Virtual Basis ai-je fait une bêtise ?
Si quelqu'un peut m'(aider svp, je touche du doigt le graal mais il me manque de l'aide, svp....
Nico
This comment was minimized by the moderator on the site
I want to add more feature in this code. For instance, once email moved to business folder, I need this email to be automatically forward to specific email address. Possible?
This comment was minimized by the moderator on the site
it works as a charm but i want to take it to the next step. using a different folder instead of the inbox for example a folder called 2020 under the head and then from there the mentioned subfolders based on Categories. i was thinking to add this line.. Set xInboxFld = Outlook.Application.Session.GetDefaultFolder(olFolderInbox).outlook.Application.Session.GetDefaultFolder(xMailItem.Categories)
This comment was minimized by the moderator on the site
worked on all mails not only after read. i created a rule mention a certain name that it gets a catergory. how can make it that it only takes the mails which are read?
This comment was minimized by the moderator on the site
This worked for me. would you be able to edit the code just to have the messages moved to one folder instead of creating one for each category. I have all the emails in one folder regardless of category and sort them in the folder.
This comment was minimized by the moderator on the site
At first this did not work for me either but after a while it just started to work, I'm not sure why though.
This comment was minimized by the moderator on the site
same here. Didn't work
This comment was minimized by the moderator on the site
Did not work.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations