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

จะบันทึกไฟล์แนบทั้งหมดจากอีเมลหลายฉบับไปยังโฟลเดอร์ใน Outlook ได้อย่างไร

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

บันทึกไฟล์แนบทั้งหมดจากอีเมลหลายฉบับไปยังโฟลเดอร์ด้วยรหัส VBA
คลิกหลายครั้งเพื่อบันทึกไฟล์แนบทั้งหมดจากอีเมลหลายฉบับไปยังโฟลเดอร์ด้วยเครื่องมือที่น่าทึ่ง


บันทึกไฟล์แนบทั้งหมดจากอีเมลหลายฉบับไปยังโฟลเดอร์ด้วยรหัส VBA

ส่วนนี้แสดงรหัส VBA ในคำแนะนำทีละขั้นตอนเพื่อช่วยให้คุณบันทึกไฟล์แนบทั้งหมดจากอีเมลหลายฉบับไปยังโฟลเดอร์ที่ระบุพร้อมกันได้อย่างรวดเร็ว กรุณาดำเนินการดังนี้

1. ประการแรกคุณต้องสร้างโฟลเดอร์สำหรับบันทึกไฟล์แนบในคอมพิวเตอร์ของคุณ

เข้าสู่ เอกสาร โฟลเดอร์และสร้างโฟลเดอร์ชื่อ “ ไฟล์แนบ” ดูภาพหน้าจอ:

2. เลือกอีเมลที่คุณจะบันทึกไฟล์แนบจากนั้นกด อื่น ๆ + F11 คีย์เพื่อเปิด Microsoft Visual Basic สำหรับแอปพลิเคชัน หน้าต่าง

3 คลิก สิ่งที่ใส่เข้าไป > โมดูล เพื่อเปิด โมดูล จากนั้นคัดลอกรหัส VBA ต่อไปนี้ลงในหน้าต่าง

รหัส VBA 1: บันทึกไฟล์แนบจำนวนมากจากอีเมลหลายฉบับ (บันทึกไฟล์แนบชื่อเดียวกันโดยตรง)

เคล็ดลับ: รหัสนี้จะบันทึกไฟล์แนบชื่อเดียวกันโดยเพิ่มตัวเลข 1, 2, 3 ... หลังชื่อไฟล์

Dim GCount As Integer
Dim GFilepath As String
Public Sub SaveAttachments()
'Update 20200821
Dim xMailItem As Outlook.MailItem
Dim xAttachments As Outlook.Attachments
Dim xSelection As Outlook.Selection
Dim i As Long
Dim xAttCount As Long
Dim xFilePath As String, xFolderPath As String, xSaveFiles As String
On Error Resume Next
xFolderPath = CreateObject("WScript.Shell").SpecialFolders(16)
Set xSelection = Outlook.Application.ActiveExplorer.Selection
xFolderPath = xFolderPath & "\Attachments\"
If VBA.Dir(xFolderPath, vbDirectory) = vbNullString Then
    VBA.MkDir xFolderPath
End If
GFilepath = ""
For Each xMailItem In xSelection
    Set xAttachments = xMailItem.Attachments
    xAttCount = xAttachments.Count
    xSaveFiles = ""
    If xAttCount > 0 Then
        For i = xAttCount To 1 Step -1
            GCount = 0
            xFilePath = xFolderPath & xAttachments.Item(i).FileName
            GFilepath = xFilePath
            xFilePath = FileRename(xFilePath)
            If IsEmbeddedAttachment(xAttachments.Item(i)) = False Then
                xAttachments.Item(i).SaveAsFile xFilePath
                If xMailItem.BodyFormat <> olFormatHTML Then
                    xSaveFiles = xSaveFiles & vbCrLf & "<Error! Hyperlink reference not valid.>"
                Else
                    xSaveFiles = xSaveFiles & "<br>" & "<a href='file://" & xFilePath & "'>" & xFilePath & "</a>"
                End If
            End If
        Next i
    End If
Next
Set xAttachments = Nothing
Set xMailItem = Nothing
Set xSelection = Nothing
End Sub

Function FileRename(FilePath As String) As String
Dim xPath As String
Dim xFso As FileSystemObject
On Error Resume Next
Set xFso = CreateObject("Scripting.FileSystemObject")
xPath = FilePath
FileRename = xPath
If xFso.FileExists(xPath) Then
    GCount = GCount + 1
    xPath = xFso.GetParentFolderName(GFilepath) & "\" & xFso.GetBaseName(GFilepath) & " " & GCount & "." + xFso.GetExtensionName(GFilepath)
    FileRename = FileRename(xPath)
End If
xFso = Nothing
End Function

Function IsEmbeddedAttachment(Attach As Attachment)
Dim xItem As MailItem
Dim xCid As String
Dim xID As String
Dim xHtml As String
On Error Resume Next
IsEmbeddedAttachment = False
Set xItem = Attach.Parent
If xItem.BodyFormat <> olFormatHTML Then Exit Function
xCid = ""
xCid = Attach.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001F")
If xCid <> "" Then
    xHtml = xItem.HTMLBody
    xID = "cid:" & xCid
    If InStr(xHtml, xID) > 0 Then
        IsEmbeddedAttachment = True
    End If
End If
End Function
รหัส VBA 2: บันทึกไฟล์แนบจำนวนมากจากอีเมลหลายฉบับ (ตรวจสอบรายการที่ซ้ำกัน)
Public Sub SaveAttachments()
'Update 20200821
Dim xMailItem As Outlook.MailItem
Dim xAttachments As Outlook.Attachments
Dim xSelection As Outlook.Selection
Dim i As Long
Dim xAttCount As Long
Dim xFilePath As String, xFolderPath As String, xSaveFiles As String
Dim xYesNo As Integer
Dim xFlag As Boolean
On Error Resume Next
xFolderPath = CreateObject("WScript.Shell").SpecialFolders(16)
Set xSelection = Outlook.Application.ActiveExplorer.Selection
xFolderPath = xFolderPath & "\Attachments\"
If VBA.Dir(xFolderPath, vbDirectory) = vbNullString Then
    VBA.MkDir xFolderPath
End If
For Each xMailItem In xSelection
    Set xAttachments = xMailItem.Attachments
    xAttCount = xAttachments.Count
    xSaveFiles = ""
    If xAttCount > 0 Then
        For i = xAttCount To 1 Step -1
            xFilePath = xFolderPath & xAttachments.Item(i).FileName
            xFlag = True
            If VBA.Dir(xFilePath, 16) <> Empty Then
                xYesNo = MsgBox("The file is exists, do you want to replace it", vbYesNo + vbInformation, "Kutools for Outlook")
                If xYesNo = vbNo Then xFlag = False
            End If
            If xFlag = True Then
                xAttachments.Item(i).SaveAsFile xFilePath
                If xMailItem.BodyFormat <> olFormatHTML Then
                    xSaveFiles = xSaveFiles & vbCrLf & "<Error! Hyperlink reference not valid.>"
                Else
                    xSaveFiles = xSaveFiles & "<br>" & "<a href='file://" & xFilePath & "'>" & xFilePath & "</a>"
                End If
            End If
        Next i
    End If
Next
Set xAttachments = Nothing
Set xMailItem = Nothing
Set xSelection = Nothing
End Sub

หมายเหตุ / รายละเอียดเพิ่มเติม:

1) หากคุณต้องการบันทึกไฟล์แนบชื่อเดียวกันทั้งหมดในโฟลเดอร์โปรดใช้ข้อมูลข้างต้น รหัส VBA 1. ก่อนเรียกใช้รหัสนี้โปรดคลิก เครื่องมือ > อ้างอิงจากนั้นตรวจสอบไฟล์ รันไทม์การเขียนสคริปต์ของ Microsoft กล่องใน เอกสารอ้างอิง - โครงการ กล่องโต้ตอบ;

doc บันทึกไฟล์แนบ 07

2) หากคุณต้องการตรวจสอบชื่อไฟล์แนบที่ซ้ำกันโปรดใช้รหัส VBA 2 หลังจากเรียกใช้รหัสกล่องโต้ตอบจะปรากฏขึ้นเพื่อเตือนคุณว่าจะแทนที่ไฟล์แนบที่ซ้ำกันหรือไม่ให้เลือก ใช่ or ไม่ ขึ้นอยู่กับความต้องการของคุณ

5 กด F5 กุญแจสำคัญในการเรียกใช้รหัส

จากนั้นสิ่งที่แนบมาทั้งหมดในอีเมลที่เลือกจะถูกบันทึกลงในโฟลเดอร์ที่คุณสร้างในขั้นตอนที่ 1 

หมายเหตุ: อาจมีไฟล์ Microsoft Outlook กล่องข้อความปรากฏขึ้นโปรดคลิกที่ อนุญาต เพื่อดำเนินการต่อ


บันทึกไฟล์แนบทั้งหมดจากอีเมลหลายฉบับไปยังโฟลเดอร์ด้วยเครื่องมือที่น่าทึ่ง

หากคุณเป็นมือใหม่ใน VBA ขอแนะนำที่นี่ บันทึกไฟล์แนบทั้งหมด ประโยชน์ของ Kutools สำหรับ Outook สำหรับคุณ. ด้วยยูทิลิตี้นี้คุณสามารถบันทึกไฟล์แนบทั้งหมดจากอีเมลหลายฉบับพร้อมกันได้อย่างรวดเร็วด้วยการคลิกหลายครั้งใน Outlook เท่านั้น
ก่อนใช้คุณลักษณะนี้โปรด ดาวน์โหลดและติดตั้ง Kutools for Outlook ก่อนอื่น.

1. เลือกอีเมลที่มีไฟล์แนบที่คุณต้องการบันทึก

ทิปส์: คุณสามารถเลือกอีเมลที่ไม่อยู่ติดกันได้โดยกดปุ่ม Ctrl คีย์และเลือกทีละรายการ
หรือเลือกอีเมลหลายฉบับที่อยู่ติดกันโดยกดปุ่ม เปลี่ยน คีย์และเลือกอีเมลแรกและอีเมลสุดท้าย

2 คลิก Kutools >เครื่องมือแนบบันทึกทั้งหมด. ดูภาพหน้าจอ:

3 ใน บันทึกการตั้งค่า คลิกที่ เพื่อเลือกโฟลเดอร์ที่จะบันทึกไฟล์แนบจากนั้นคลิกปุ่ม OK ปุ่ม

3 คลิก OK สองครั้งในกล่องโต้ตอบถัดไปที่ปรากฏขึ้นจากนั้นไฟล์แนบทั้งหมดในอีเมลที่เลือกจะถูกบันทึกในโฟลเดอร์ที่ระบุพร้อมกัน

หมายเหตุ:

  • 1. หากคุณต้องการบันทึกไฟล์แนบในโฟลเดอร์ต่างๆตามอีเมลโปรดตรวจสอบไฟล์ สร้างโฟลเดอร์ย่อยในลักษณะต่อไปนี้ แล้วเลือกสไตล์โฟลเดอร์จากเมนูแบบเลื่อนลง
  • 2. นอกจากบันทึกไฟล์แนบทั้งหมดแล้วคุณสามารถบันทึกไฟล์แนบตามเงื่อนไขเฉพาะได้ ตัวอย่างเช่นคุณต้องการบันทึกเฉพาะไฟล์แนบ pdf ที่ชื่อไฟล์มีคำว่า "Invoice" โปรดคลิกที่ ตัวเลือกขั้นสูง เพื่อขยายเงื่อนไขจากนั้นกำหนดค่าตามที่แสดงด้านล่าง screebshot
  • 3. หากคุณต้องการบันทึกไฟล์แนบโดยอัตโนมัติเมื่อมีอีเมลมาถึงไฟล์ บันทึกไฟล์แนบอัตโนมัติ คุณสมบัติสามารถช่วยได้
  • 4. สำหรับการแยกไฟล์แนบออกจากอีเมลที่เลือกโดยตรงไฟล์ ถอดไฟล์แนบทั้งหมด คุณลักษณะของ Kutools สำหรับ Outlook สามารถช่วยคุณได้

  หากคุณต้องการทดลองใช้ยูทิลิตีนี้ฟรี (60 วัน) กรุณาคลิกเพื่อดาวน์โหลดแล้วไปใช้การดำเนินการตามขั้นตอนข้างต้น


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

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

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

พิมพ์ไฟล์แนบทั้งหมดในอีเมลเดียว / หลายฉบับใน Outlook
ดังที่คุณทราบจะพิมพ์เฉพาะเนื้อหาอีเมลเช่นส่วนหัวเนื้อหาเมื่อคุณคลิกไฟล์> พิมพ์ใน Microsoft Outlook แต่ไม่พิมพ์ไฟล์แนบ ที่นี่เราจะแสดงวิธีพิมพ์ไฟล์แนบทั้งหมดในอีเมลที่เลือกอย่างสบายใจใน Microsoft Outlook

ค้นหาคำภายในไฟล์แนบ (เนื้อหา) ใน Outlook
เมื่อเราพิมพ์คำสำคัญในช่องค้นหาทันทีใน Outlook มันจะค้นหาคำสำคัญในหัวเรื่องเนื้อหาไฟล์แนบ ฯลฯ ของอีเมล แต่ตอนนี้ฉันต้องการค้นหาคำสำคัญในเนื้อหาไฟล์แนบใน Outlook เท่านั้นมีความคิดอย่างไร บทความนี้แสดงขั้นตอนโดยละเอียดในการค้นหาคำภายในเนื้อหาไฟล์แนบใน Outlook ได้อย่างง่ายดาย

เก็บไฟล์แนบเมื่อตอบกลับใน Outlook
เมื่อเราส่งต่อข้อความอีเมลใน Microsoft Outlook ไฟล์แนบต้นฉบับในข้อความอีเมลนี้จะยังคงอยู่ในข้อความที่ส่งต่อ อย่างไรก็ตามเมื่อเราตอบกลับข้อความอีเมลไฟล์แนบต้นฉบับจะไม่ถูกแนบมาในข้อความตอบกลับใหม่ ที่นี่เราจะแนะนำเทคนิคสองสามประการเกี่ยวกับการเก็บไฟล์แนบต้นฉบับเมื่อตอบกลับใน Microsoft Outlook


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

Kutools สำหรับ Outlook - คุณสมบัติอันทรงพลังมากกว่า 100 รายการเพื่อเติมพลังให้กับ Outlook ของคุณ

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

📧 การทำงานอัตโนมัติของอีเมล: ไม่อยู่ที่สำนักงาน (ใช้ได้กับ POP และ IMAP)  /  กำหนดการส่งอีเมล  /  Auto CC/BCC ตามกฎเมื่อส่งอีเมล  /  ส่งต่ออัตโนมัติ (กฎขั้นสูง)   /  เพิ่มคำทักทายอัตโนมัติ   /  แบ่งอีเมลผู้รับหลายรายออกเป็นข้อความส่วนตัวโดยอัตโนมัติ ...

📨 การจัดการอีเมล์: เรียกคืนอีเมลได้อย่างง่ายดาย  /  บล็อกอีเมลหลอกลวงตามหัวเรื่องและอื่นๆ  /  ลบอีเมลที่ซ้ำกัน  /  การค้นหาขั้นสูง  /  รวมโฟลเดอร์ ...

📁 ไฟล์แนบโปรบันทึกแบทช์  /  การแยกแบทช์  /  การบีบอัดแบบแบตช์  /  บันทึกอัตโนมัติ   /  ถอดอัตโนมัติ  /  บีบอัดอัตโนมัติ ...

🌟 อินเตอร์เฟซเมจิก: 😊อีโมจิที่สวยและเจ๋งยิ่งขึ้น   /  เพิ่มประสิทธิภาพการทำงาน Outlook ของคุณด้วยมุมมองแบบแท็บ  /  ลดขนาด Outlook แทนที่จะปิด ...

???? เพียงคลิกเดียวสิ่งมหัศจรรย์: ตอบกลับทั้งหมดด้วยไฟล์แนบที่เข้ามา  /   อีเมลต่อต้านฟิชชิ่ง  /  🕘 แสดงโซนเวลาของผู้ส่ง ...

👩🏼‍🤝‍👩🏻 รายชื่อและปฏิทิน: แบทช์เพิ่มผู้ติดต่อจากอีเมลที่เลือก  /  แบ่งกลุ่มผู้ติดต่อเป็นกลุ่มแต่ละกลุ่ม  /  ลบการแจ้งเตือนวันเกิด ...

เกิน คุณสมบัติ 100 รอการสำรวจของคุณ! คลิกที่นี่เพื่อค้นพบเพิ่มเติม

 

 

Comments (81)
Rated 3.5 out of 5 · 3 ratings
This comment was minimized by the moderator on the site
Thank you for sharing the code. Unfortunately, I tried both with failure. This is what I got - The macros in this project are disabled. Please refer to the online help or documentation of the host application to determine how to enable macros. Thank you.
This comment was minimized by the moderator on the site
Hi,
Please follow the instructions in the screenshot below to check if macros are enabled in the macro settings in your Outlook. After enabling both options, re-run the VBA code.

https://www.extendoffice.com/images/stories/comments/comment-picture-zxm/macro-enabled.png
This comment was minimized by the moderator on the site
Thank you so much.
Rated 5 out of 5
This comment was minimized by the moderator on the site
Thank you for sharing VBA code. This work like magic and is going to save it lots of time!
This comment was minimized by the moderator on the site
Hello friends!

Thanks for sharing this VBA code.

Is there any way to change the location of the save folder?

I share the pc with some colleagues and in this case I need the files to be saved in a password protected folder which is not located in the documents folder.

How can I make this change?

Thank you in advance
This comment was minimized by the moderator on the site
Hi Fabiana,
Change the line 14
xFolderPath = xFolderPath & "\Attachments\"

to
xFolderPath = "C:\Users\Win10x64Test\Desktop\save attachments\1\"

Here "C:\Users\Win10x64Test\Desktop\save attachments\1\" is the folder path in my case.
Don't forget to end the folder path with a slash "\"
This comment was minimized by the moderator on the site
Hello friends!

Thank you for sharing that VBA code.

Is there any way to change the location of the save folder?

I share the pc with some colleagues and in this case I need the files to be saved in a password protected folder which is not located in the documents folder.

How can I make this change?

Thank you in advance
This comment was minimized by the moderator on the site
If you are trying to run the Code that renames duplicate files and keep getting a "User Type Not Defined" error message here is the code fixed. Instead of the "Dim xFso As FileSystemObject" on line 47 it should be "Dim xFso As Variant"
Also added a Message Box to appear at the end of data transfer.

Dim GCount As Integer
Dim GFilepath As String
Public Sub SaveAttachments()
'Update 20200821
Dim xMailItem As Outlook.MailItem
Dim xAttachments As Outlook.Attachments
Dim xSelection As Outlook.Selection
Dim i As Long
Dim xAttCount As Long
Dim xFilePath As String, xFolderPath As String, xSaveFiles As String
On Error Resume Next
xFolderPath = CreateObject("WScript.Shell").SpecialFolders(16)
Set xSelection = Outlook.Application.ActiveExplorer.Selection
xFolderPath = xFolderPath & "\Attachments\"
If VBA.Dir(xFolderPath, vbDirectory) = vbNullString Then
VBA.MkDir xFolderPath
End If
GFilepath = ""
For Each xMailItem In xSelection
Set xAttachments = xMailItem.Attachments
xAttCount = xAttachments.Count
xSaveFiles = ""
If xAttCount > 0 Then
For i = xAttCount To 1 Step -1
GCount = 0
xFilePath = xFolderPath & xAttachments.Item(i).FileName
GFilepath = xFilePath
xFilePath = FileRename(xFilePath)
If IsEmbeddedAttachment(xAttachments.Item(i)) = False Then
xAttachments.Item(i).SaveAsFile xFilePath
If xMailItem.BodyFormat <> olFormatHTML Then
xSaveFiles = xSaveFiles & vbCrLf & "<Error! Hyperlink reference not valid.>"
Else
xSaveFiles = xSaveFiles & "<br>" & "<a href='file://" & xFilePath & "'>" & xFilePath & "</a>"
End If
End If
Next i
End If
Next
Set xAttachments = Nothing
Set xMailItem = Nothing
Set xSelection = Nothing
MsgBoX prompt:="File Transfer Complete", Title:="Sweatyjalapenos tha Goat"
End Sub

Function FileRename(FilePath As String) As String
Dim xPath As String
Dim xFso As Variant
On Error Resume Next
Set xFso = CreateObject("Scripting.FileSystemObject")
xPath = FilePath
FileRename = xPath
If xFso.FileExists(xPath) Then
GCount = GCount + 1
xPath = xFso.GetParentFolderName(GFilepath) & "\" & xFso.GetBaseName(GFilepath) & " " & GCount & "." + xFso.GetExtensionName(GFilepath)
FileRename = FileRename(xPath)
End If
xFso = Nothing
End Function

Function IsEmbeddedAttachment(Attach As Attachment)
Dim xItem As MailItem
Dim xCid As String
Dim xID As String
Dim xHtml As String
On Error Resume Next
IsEmbeddedAttachment = False
Set xItem = Attach.Parent
If xItem.BodyFormat <> olFormatHTML Then Exit Function
xCid = ""
xCid = Attach.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001F")
If xCid <> "" Then
xHtml = xItem.HTMLBody
xID = "cid:" & xCid
If InStr(xHtml, xID) > 0 Then
IsEmbeddedAttachment = True

End If
End If
End Function
This comment was minimized by the moderator on the site
Very nice script as of 2022-10-19 works great, for me doesn't seem to change original message by adding text. The only thing I changed is I added message received date time to each file name with the following format so it would nicely sort by date time in Windows folder: "yyyy-mm-dd HH-mm-ss ".

Code:

Dim GCount As Integer
Dim GFilepath As String
Public Sub SaveAttachments()
'Update 20200821
Dim xMailItem As Outlook.MailItem
Dim xAttachments As Outlook.Attachments
Dim xSelection As Outlook.Selection
Dim i As Long
Dim xAttCount As Long
Dim xFilePath As String, xFolderPath As String, xSaveFiles As String, xDateFormat As String
On Error Resume Next
xFolderPath = CreateObject("WScript.Shell").SpecialFolders(16)
Set xSelection = Outlook.Application.ActiveExplorer.Selection
xFolderPath = xFolderPath & "\Attachments\"
If VBA.Dir(xFolderPath, vbDirectory) = vbNullString Then
VBA.MkDir xFolderPath
End If
GFilepath = ""
For Each xMailItem In xSelection
Set xAttachments = xMailItem.Attachments
xAttCount = xAttachments.Count
xSaveFiles = ""
If xAttCount > 0 Then
For i = xAttCount To 1 Step -1
GCount = 0
xDateFormat = Format(xMailItem.ReceivedTime, "yyyy-mm-dd HH-mm-ss ")
xFilePath = xFolderPath & xDateFormat & xAttachments.Item(i).FileName
GFilepath = xFilePath
xFilePath = FileRename(xFilePath)
If IsEmbeddedAttachment(xAttachments.Item(i)) = False Then
xAttachments.Item(i).SaveAsFile xFilePath
If xMailItem.BodyFormat <> olFormatHTML Then
xSaveFiles = xSaveFiles & vbCrLf & "<Error! Hyperlink reference not valid.>"
Else
xSaveFiles = xSaveFiles & "<br>" & "<a href='file://" & xFilePath & "'>" & xFilePath & "</a>"
End If
End If
Next i
End If
Next
Set xAttachments = Nothing
Set xMailItem = Nothing
Set xSelection = Nothing
End Sub

Function FileRename(FilePath As String) As String
Dim xPath As String
Dim xFso As FileSystemObject
On Error Resume Next
Set xFso = CreateObject("Scripting.FileSystemObject")
xPath = FilePath
FileRename = xPath
If xFso.FileExists(xPath) Then
GCount = GCount + 1
xPath = xFso.GetParentFolderName(GFilepath) & "\" & xFso.GetBaseName(GFilepath) & " " & GCount & "." + xFso.GetExtensionName(GFilepath)
FileRename = FileRename(xPath)
End If
xFso = Nothing
End Function

Function IsEmbeddedAttachment(Attach As Attachment)
Dim xItem As MailItem
Dim xCid As String
Dim xID As String
Dim xHtml As String
On Error Resume Next
IsEmbeddedAttachment = False
Set xItem = Attach.Parent
If xItem.BodyFormat <> olFormatHTML Then Exit Function
xCid = ""
xCid = Attach.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001F")
If xCid <> "" Then
xHtml = xItem.HTMLBody
xID = "cid:" & xCid
If InStr(xHtml, xID) > 0 Then
IsEmbeddedAttachment = True
End If
End If
End Function
This comment was minimized by the moderator on the site
Hi Oigo,
This is a very useful VBA script. Thank you for sharing it.
This comment was minimized by the moderator on the site
Hi crystal,

sorry for not being clear.

I was trying to use the code above mentioned. However, apparently I was doing something wrong. I was thinking that I might need to amend some parts in the code shown. For instance the path where to save the attachments and maybe some other parts. Therefore I was asking if you could share the code highlighting the parts which needs tailoring and how to tailor them.

Many thanks,
BR
This comment was minimized by the moderator on the site
Hi Rokkie,
Did you get any error prompt when the code runs? Or which line in your code is highlighted? I need more details so I can see where you can modify the code.
This comment was minimized by the moderator on the site
Hey crystal,

completeley new to this VBA. Can you share a code to use which shows where I have to amend with an example? As a Rookie it is a bit difficult to figure it out.

I am working via a Ctrix connection. Could this be a blocker for the macro?

Much appreaciate the help.
This comment was minimized by the moderator on the site
Hi Rookie,
Sorry I don't understand what you mean: "Can you share a code to use which shows where I have to amend with an example?"
And the code operates on selected emails in Outlook, Ctrix Connection does not block the macro.
This comment was minimized by the moderator on the site
Hi, I am running this Code 1 to extract .txt files from separate sub-folders of an inbox. It works great out of one sub-folder but not at all out of another sub-folder. I have tried forwarding the relevant email and attachment into other inboxes but no luck. The files are automatically generated and sent to the different sub-folders and only vary by a single letter in their title

Any help much is appreciated
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations