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

จะส่งอีเมลพร้อมไฟล์แนบหลายไฟล์แนบใน Excel ได้อย่างไร

บทความนี้พูดถึงการส่งอีเมลผ่าน Outlook พร้อมแนบไฟล์แนบหลายไฟล์ใน Excel

ส่งอีเมลพร้อมไฟล์แนบหลายไฟล์แนบใน Excel พร้อมรหัส VBA


ส่งอีเมลพร้อมไฟล์แนบหลายไฟล์แนบใน Excel พร้อมรหัส VBA

โปรดทำดังนี้เพื่อส่งอีเมลพร้อมไฟล์แนบหลายไฟล์แนบใน Excel

1. กรุณาใส่ปุ่มคำสั่งโดยคลิก ผู้พัฒนา > สิ่งที่ใส่เข้าไป > ปุ่มคำสั่ง (ActiveX Control). ดูภาพหน้าจอ:

2. หลังจากใส่ปุ่ม Command แล้วโปรดคลิกขวาและเลือก ดูรหัส จากเมนูบริบท

3. ในการเปิด Microsoft Visual Basic สำหรับแอปพลิเคชัน โปรดคลิก เครื่องมือ > อ้างอิง ดังภาพด้านล่างที่แสดง

4 ใน เอกสารอ้างอิง - VBAProject โปรดค้นหาและตรวจสอบไฟล์ ไลบรารีวัตถุของ Microsoft Outlook จากนั้นคลิกตัวเลือก OK ปุ่ม

5. จากนั้นแทนที่รหัสเดิมในหน้าต่างรหัสด้วยรหัส VBA ด้านล่าง

รหัส VBA: ส่งอีเมลพร้อมไฟล์แนบหลายไฟล์ใน Excel

Private Sub CommandButton1_Click()
    Dim xStrFile As String
    Dim xFilePath As String
    Dim xFileDlg As FileDialog
    Dim xFileDlgItem As Variant
    Dim xOutApp As Outlook.Application
    Dim xMailOut As Outlook.MailItem
    Application.ScreenUpdating = False
    Set xOutApp = CreateObject("Outlook.Application")
    Set xMailOut = xOutApp.CreateItem(olMailItem)
    Set xFileDlg = Application.FileDialog(msoFileDialogFilePicker)
    If xFileDlg.Show = -1 Then
        With xMailOut
            .BodyFormat = olFormatRichText
            .To = ""
            .Subject = "test"
            .HTMLBody = "test"
            For Each xFileDlgItem In xFileDlg.SelectedItems
                .Attachments.Add xFileDlgItem
            Next xFileDlgItem
            .Display
        End With
    End If
    Set xMailOut = Nothing
    Set xOutApp = Nothing
    Application.ScreenUpdating = True
End Sub

หมายเหตุ: โปรดระบุผู้รับอีเมลหัวเรื่องและเนื้อหาของคุณโดยเปลี่ยนรูปแบบใน .ถึง = , . เรื่อง = "ทดสอบ" และ .HTMLBody = "ทดสอบ" บรรทัดในรหัส

6 กด อื่น ๆ + Q เข้าด้วยกันเพื่อออกจากไฟล์ Microsoft Visual Basic สำหรับแอปพลิเคชัน หน้าต่าง

7 คลิก ผู้พัฒนา > โหมดการออกแบบ เพื่อปิดโหมดออกแบบ ดูภาพหน้าจอ:

8. คลิกปุ่ม Command เพื่อเรียกใช้โค้ด ในการโผล่ขึ้นมา หมวดหมู่สินค้า เลือกไฟล์ที่คุณต้องการแนบในอีเมลจากนั้นคลิกไฟล์ OK ปุ่ม. ดูภาพหน้าจอ:

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

หมายเหตุ: รหัส VBA จะใช้งานได้ก็ต่อเมื่อคุณใช้ Outlook เป็นโปรแกรมอีเมลของคุณ


ส่งอีเมลผ่าน Outlook ได้อย่างง่ายดายตามช่องของรายชื่อผู้รับจดหมายที่สร้างขึ้นใน Excel

พื้นที่ ส่งอีเมลล์ ประโยชน์ของ Kutools สำหรับ Excel ช่วยให้ผู้ใช้ส่งอีเมลผ่าน Outlook ตามรายชื่อผู้รับจดหมายที่สร้างขึ้นใน Excel
ดาวน์โหลดและทดลองใช้ทันที! (เส้นทางฟรี 30 วัน)



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

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

🤖 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 (14)
Rated 5 out of 5 · 1 ratings
This comment was minimized by the moderator on the site
أريد إرسال بريد إلكتروني مع البريد أو hotmail مع CDO ولكن كل ما لدي فقط مع مرفق واحد ولكن أريد أن أرسل مع العديد من المرفقات يرجى إرسال لي عن طريق بريدي الإلكتروني الرمز أو ملف Excel
Rated 5 out of 5
This comment was minimized by the moderator on the site
Is het ook mogelijk om een filter te zetten op de selectie van de bijlagen, zodat er alleen pdf-bestanden aan de mail kunnen worden toegevoegd?
This comment was minimized by the moderator on the site
Hi Alex de Graaf,
The code directly calls the Microsoft's file selection window. This makes it easy for VBA users to select needed files.
This comment was minimized by the moderator on the site
Hi Crystal,
Yes, I do understand that. However, is it possible to restrict users to only select pdf-files?
This comment was minimized by the moderator on the site
Hi Crystal,

Yes, I understand that. However I want the users to only be able to select pdf-files.
Is this possible?
This comment was minimized by the moderator on the site
Hi Alex de Graaf,
The following VBA code lists only the PDF files in the Browse window. Please give it a try.

Private Sub CommandButton1_Click()
'Updated by Extendoffice 20220714
    Dim xStrFile As String
    Dim xFilePath As String
    Dim xFileDlg As FileDialog
    Dim xFileDlgItem As Variant
    Dim xOutApp As Outlook.Application
    Dim xMailOut As Outlook.MailItem
    Application.ScreenUpdating = False
    Set xOutApp = CreateObject("Outlook.Application")
    Set xMailOut = xOutApp.CreateItem(olMailItem)
    Set xFileDlg = Application.FileDialog(msoFileDialogFilePicker)
    xFileDlg.Filters.Add "PDF", "*.pdf", 1
xFileDlg.FilterIndex = 1
    If xFileDlg.Show = -1 Then
        With xMailOut
            .BodyFormat = olFormatRichText
            .To = ""
            .Subject = "test"
            .HTMLBody = "test"
            For Each xFileDlgItem In xFileDlg.SelectedItems
                .Attachments.Add xFileDlgItem
            Next xFileDlgItem
            .Display
        End With
    End If
    Set xMailOut = Nothing
    Set xOutApp = Nothing
    Application.ScreenUpdating = True
End Sub
This comment was minimized by the moderator on the site
Hola,
Me gustaría saber como quedaría la macro si quisiera enviar en un mismo correo a varias personas o más y con varios ficheros o más.
Muchas gracias.
This comment was minimized by the moderator on the site
I have enjoyed working through this solution for adding multiple attachments to an email from within Excel VBA. Thank you. I know that a lot of us benefit and then want some aspect customized for exactly what we are trying to do. I am no different, but for step 8. Can we set the path that the Browse window will open with? I can browse over to another folder at a different location but if I could set the path that would be a time saver.
This comment was minimized by the moderator on the site
Superb...... Works perfectly.
This comment was minimized by the moderator on the site
HI Team ....i am unable to see the attachment in mail so if i follow the your step...can you pls help
This comment was minimized by the moderator on the site
the above code works perfectly thanks!! but my email automatic signature seem to disappear with this code. any idea why?
This comment was minimized by the moderator on the site
What if multiple different user and different attachment to be send with different subject line.
This comment was minimized by the moderator on the site
What if above files are located in sub-folders? How to look for a file in folder and sub-folders?
This comment was minimized by the moderator on the site
I am able to "Quickly send email with multiple attachments attached in Excel with Kutools for Excel" using your steps above, but would like to take it one step further and personalize each email by inserting their names (from a column in the Excel sheet) into the body of the email. While in the body of the email, I try selecting the field and clicking on "Insert Placeholder" but nothing happens. Any idea why or how I can fix this? Thank you!
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations