Loncat ke daftar isi utama

Bagaimana cara mengirim email dengan banyak lampiran yang dilampirkan di Excel?

Artikel ini membahas tentang mengirim email melalui Outlook dengan beberapa lampiran yang dilampirkan di Excel.

Kirim email dengan beberapa lampiran yang dilampirkan di Excel dengan kode VBA


Kirim email dengan beberapa lampiran yang dilampirkan di Excel dengan kode VBA

Harap lakukan hal berikut untuk mengirim email dengan beberapa lampiran yang dilampirkan di Excel.

1. Harap masukkan tombol perintah dengan mengklik Pengembang > Menyisipkan > Tombol Perintah (Kontrol ActiveX). Lihat tangkapan layar:

2. Setelah memasukkan Command Button, klik kanan dan pilih Lihat kode dari menu konteks

3. Dalam pembukaan Microsoft Visual Basic untuk Aplikasi jendela, silakan klik Tools > Referensi seperti gambar di bawah ini.

4. Dalam Referensi - VBAProject kotak dialog, silakan temukan dan centang Perpustakaan Objek Microsoft Outlook opsi, dan kemudian klik OK .

5. Kemudian ganti kode asli di jendela Kode dengan kode VBA di bawah ini.

Kode VBA: Kirim email yang dilampirkan dengan beberapa lampiran di 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

Note: harap tentukan penerima email, subjek, dan badan email Anda dengan mengubah variasinya di .Untuk = , .Subject = "test" dan .HTMLBody = "test" baris dalam kode.

6. tekan lain + Q kunci bersama untuk keluar dari Microsoft Visual Basic untuk Aplikasi jendela.

7. klik Pengembang > Mode Desain untuk mematikan Mode Desain. Lihat tangkapan layar:

8. Klik Tombol Perintah untuk menjalankan kode. Dalam bermunculan Browse jendela, pilih file yang perlu Anda lampirkan di email, lalu klik OK tombol. Lihat tangkapan layar:

9. Kemudian email dibuat dengan kolom tertentu dan lampiran terdaftar. Silakan klik Kirim tombol untuk mengirimkannya. Lihat tangkapan layar:

Note: Kode VBA hanya berfungsi saat Anda menggunakan Outlook sebagai program email Anda.


Kirim email dengan mudah melalui Outlook berdasarkan bidang milis yang dibuat di Excel:

Grafik Mengirim email kegunaan Kutools untuk Excel membantu pengguna mengirim email melalui Outlook berdasarkan milis yang dibuat di Excel.
Unduh dan coba sekarang! (Jejak gratis 30 hari)



Artikel terkait:

Alat Produktivitas Kantor Terbaik

馃 Kutools AI Ajudan: Merevolusi analisis data berdasarkan: Eksekusi Cerdas   |  Hasilkan Kode  |  Buat Rumus Khusus  |  Analisis Data dan Hasilkan Grafik  |  Aktifkan Fungsi Kutools...
Fitur Populer: Temukan, Sorot, atau Identifikasi Duplikat   |  Hapus Baris Kosong   |  Gabungkan Kolom atau Sel tanpa Kehilangan Data   |   Putaran tanpa Formula ...
Pencarian Super: VLookup Beberapa Kriteria    VLookup Nilai Berganda  |   VLookup di Beberapa Lembar   |   Pencarian Fuzzy ....
Daftar Drop-down Lanjutan: Buat Daftar Drop Down dengan Cepat   |  Daftar Drop Down yang Bergantung   |  Multi-pilih Drop Down List ....
Manajer Kolom: Tambahkan Jumlah Kolom Tertentu  |  Pindahkan Kolom  |  Alihkan Status Visibilitas Kolom Tersembunyi  |  Bandingkan Rentang & Kolom ...
Fitur Unggulan: Fokus Kisi   |  Tampilan Desain   |   Bar Formula Besar    Manajer Buku Kerja & Lembar   |  Perpustakaan Sumberdaya (Teks otomatis)   |  Pemetik tanggal   |  Gabungkan Lembar Kerja   |  Enkripsi/Dekripsi Sel    Kirim Email berdasarkan Daftar   |  Filter Super   |   Filter Khusus (filter tebal/miring/coret...) ...
15 Perangkat Teratas12 Teks Tools (Tambahkan Teks, Hapus Karakter, ...)   |   50 + Grafik jenis (Gantt Chart, ...)   |   40+ Praktis Rumus (Hitung usia berdasarkan ulang tahun, ...)   |   19 Insersi Tools (Masukkan Kode QR, Sisipkan Gambar dari Jalur, ...)   |   12 Konversi Tools (Angka ke Kata, Konversi Mata Uang, ...)   |   7 Gabungkan & Pisahkan Tools (Lanjutan Gabungkan Baris, Pisahkan Sel, ...)   |   ... dan banyak lagi

Tingkatkan Keterampilan Excel Anda dengan Kutools for Excel, dan Rasakan Efisiensi yang Belum Pernah Ada Sebelumnya. Kutools for Excel Menawarkan Lebih dari 300 Fitur Lanjutan untuk Meningkatkan Produktivitas dan Menghemat Waktu.  Klik Di Sini untuk Mendapatkan Fitur yang Paling Anda Butuhkan...

Deskripsi Produk


Tab Office Membawa antarmuka Tab ke Office, dan Membuat Pekerjaan Anda Jauh Lebih Mudah

  • Aktifkan pengeditan dan pembacaan tab di Word, Excel, PowerPoint, Publisher, Access, Visio, dan Project.
  • Buka dan buat banyak dokumen di tab baru di jendela yang sama, bukan di jendela baru.
  • Meningkatkan produktivitas Anda sebesar 50%, dan mengurangi ratusan klik mouse untuk Anda setiap hari!
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