Note: The other languages of the website are Google-translated. Back to English
Masuk  \/ 
x
or
x
Daftar  \/ 
x

or

Bagaimana cara mengirim email melalui Outlook saat buku kerja disimpan di Excel?

Artikel ini berbicara tentang mengirim email melalui Outlook saat buku kerja tertentu disimpan di Excel. Harap lakukan seperti yang ditunjukkan tutorial.

Kirim email melalui Outlook saat buku kerja disimpan dengan kode VBA


Kirim email melalui Outlook saat buku kerja disimpan dengan kode VBA


Untuk mengirim email melalui Outlook saat buku kerja disimpan di Excel, lakukan hal berikut.

1. Harap simpan buku kerja sebagai Buku Kerja Excel Macro-Enabled pada awalnya. Klik fillet > Save As. di Save As kotak dialog, pilih folder untuk menyimpan buku kerja, beri nama di kotak Nama file, pilih Buku Kerja Excel dengan Makro Aktif dari Save as type daftar drop-down, dan kemudian klik Hemat tombol. Lihat tangkapan layar:

2. Buka Buku Kerja Excel Macro-Enabled yang baru saja Anda simpan, tekan lain + F11 tombol secara bersamaan untuk membuka Microsoft Visual Basic untuk Aplikasi jendela.

2. Dalam Microsoft Visual Basic untuk Aplikasi jendela, silakan klik dua kali Buku Kerja Ini di bilah kiri, lalu salin dan tempel kode VBA di bawah ini ke file Buku Kerja Ini jendela kode. Lihat tangkapan layar:

Kode VBA: Kirim email saat buku kerja disimpan

Private Sub Workbook_AfterSave(ByVal Success As Boolean)
'Updated by Extendoffice 20181102
    Dim xOutApp As Object
    Dim xMailItem As Object
    Dim xName As String
    On Error Resume Next
    Set xOutApp = CreateObject("Outlook.Application")
    Set xMailItem = xOutApp.CreateItem(0)
    xName = ActiveWorkbook.FullName
    With xMailItem
        .To = "Email Address"
        .CC = ""
        .Subject = "The workbook has been saved"
        .Body = "Hi," & Chr(13) & Chr(13) & "File is now updated."
        .Attachments.Add xName
        .Display
       '.send
    End With
    Set xMailItem = Nothing
    Set xOutApp = Nothing
End Sub

Catatan: Harap ganti Alamat Email dengan alamat email penerima sejalan .To = "Alamat Email", dan ubah kolom Cc, Subjek, dan isi di kode VBA sesuai kebutuhan Anda.

3. tekan lain + Q tombol secara bersamaan untuk menutup Microsoft Visual Basic untuk Aplikasi jendela.

Mulai sekarang, saat Anda memperbarui buku kerja dan menyimpannya, email akan dibuat secara otomatis dengan melampirkan buku kerja yang diperbarui. Silakan klik Kirim tombol untuk mengirim email. Lihat tangkapan layar:

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


Artikel terkait:


Alat Produktivitas Kantor Terbaik

Kutools for Excel Memecahkan Sebagian Besar Masalah Anda, dan Meningkatkan Produktivitas Anda hingga 80%

  • Reuse: Masukkan dengan cepat rumus, bagan yang kompleks dan apa pun yang pernah Anda gunakan sebelumnya; Enkripsi Sel dengan kata sandi; Buat Milis dan mengirim email ...
  • Super Formula Bar (dengan mudah mengedit beberapa baris teks dan rumus); Membaca Tata Letak (membaca dan mengedit sel dalam jumlah besar dengan mudah); Tempel ke Rentang yang Difilter...
  • Gabungkan Sel / Baris / Kolom tanpa kehilangan Data; Pisahkan Konten Sel; Gabungkan Baris / Kolom Duplikat... Mencegah Sel Duplikat; Bandingkan Rentang...
  • Pilih Duplikat atau Unik Baris; Pilih Baris Kosong (semua sel kosong); Temukan Super dan Temukan Fuzzy di Banyak Buku Kerja; Pilih Acak ...
  • Salinan Tepat Beberapa Sel tanpa mengubah referensi rumus; Buat Referensi Otomatis ke Beberapa Lembar; Sisipkan Poin, Kotak Centang, dan lainnya ...
  • Ekstrak Teks, Tambahkan Teks, Hapus berdasarkan Posisi, Hapus Space; Membuat dan Mencetak Subtotal Paging; Konversi Konten Antar Sel dan Komentar...
  • Filter Super (simpan dan terapkan skema filter ke sheet lain); Penyortiran Lanjutan menurut bulan / minggu / hari, frekuensi dan lainnya; Filter Khusus dengan huruf tebal, miring ...
  • Gabungkan Workbooks dan WorkSheets; Gabungkan Tabel berdasarkan kolom kunci; Pisahkan Data menjadi Beberapa Lembar; Konversi Batch xls, xlsx dan PDF...
  • Lebih dari 300 fitur canggih. Mendukung Office / Excel 2007-2019 dan 365. Mendukung semua bahasa. Penerapan yang mudah di perusahaan atau organisasi Anda. Fitur lengkap uji coba gratis 30 hari. Jaminan uang kembali 60 hari.
tab kte 201905

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.
  • Tingkatkan produktivitas Anda hingga 50%, dan kurangi ratusan klik mouse untuk Anda setiap hari!
officetab bawah
Say something here...
symbols left.
You are guest
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    florin · 1 years ago
    Dear All, can some one help me, I'm a novice in VBA coding, I have made some modification, but how can I do so send email if the workbook is saved, and if user name is different, like if user name of the station is glade2 then send email if the workbook is saved, else do not send.

    Thank you so much for your support
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Hi florin,
      Didn't get your point. What does your username represent?
      • To post as a guest, your comment is unpublished.
        Florin Dan · 1 years ago
        Hi crystal, thank you for your reply, usernane is enviroment usernane, and i have done it, i did use a if function and exit sub.
        Thank you so much.
  • To post as a guest, your comment is unpublished.
    Brent · 1 years ago
    Hello - How can I include cell data in the email "cc" field?
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Hi Brent,
      Supposing you want to include the value in cell a7 in the email "cc" field, please try the below VBA.

      Private Sub Workbook_AfterSave(ByVal Success As Boolean)
      'Updated by Extendoffice 20200628
      Dim xOutApp As Object
      Dim xMailItem As Object
      Dim xName As String
      On Error Resume Next
      Set xOutApp = CreateObject("Outlook.Application")
      Set xMailItem = xOutApp.CreateItem(0)
      xName = ActiveWorkbook.FullName
      With xMailItem
      .To = "Email Address"
      .CC = Range("a7").Value
      .Subject = "The workbook has been saved"
      .Body = "Hi," & Chr(13) & Chr(13) & "File is now updated."
      .Attachments.Add xName
      .Display
      '.send
      End With
      Set xMailItem = Nothing
      Set xOutApp = Nothing
      End Sub
  • To post as a guest, your comment is unpublished.
    Lena · 1 years ago
    Hi! Thanks a lot for this guideline :-) I would like to do something more in this code - send an email based on the countries. It means that I have to create commands with if and select. Right? I have already delete the attachment from email. I would like to add the link with path into folder instead. But when macro run, command is not valid :-(
    I appreciate each help how to add it there.
  • To post as a guest, your comment is unpublished.
    Mike · 2 years ago
    Is there a way to have the automated email be auto encrypted?
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Hi Mike,
      Sorry can't help to solve this problem. Thank you for your comment.
  • To post as a guest, your comment is unpublished.
    mayle4pam · 2 years ago
    How would this be handled for an Office 365 document. It is automatically saving.
  • To post as a guest, your comment is unpublished.
    Chris · 2 years ago
    Hi, nice article! One thing ive been trying to achieve with this is to attach the current state of the workbook to the email.

    At the moment, it only sends the original state of the file and doesnt include any changes the user would have made.

    Any ideas on how to implement this using a macro?
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Hi Chris,
      The code has been updated with the problem solved, please have a try. Thank you for your comment.
      • To post as a guest, your comment is unpublished.
        Tin Hwee Lee · 2 years ago
        Hi Chris,

        I have chanced upon the same issue.
        Currently the codes are used in the "beforesave" module.
        Which means that the email will send the spreadsheet that is before saved.

        There is another module "aftersave".
        I applied the code in this module and it worked like a charm.
  • To post as a guest, your comment is unpublished.
    Bob · 2 years ago
    Dear all, I would like to ask how to attach functional link to certain folder on server, if I paste the link, it appears in the workbook just like plain text and so it doensn't work in received e-mail, how can I turn it into link, so recepiants can click on it?
    I would like to use this way instead sending enclosed excel file.
    Thanks for advice
    • To post as a guest, your comment is unpublished.
      Grant · 2 years ago
      I put this in the body of the email and it worked for me...
      "file:///Z:\dir1\dir2\dir3\Test1.xlsm"
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Hi Robert,
      Sorry can’t help with this, welcome to post any question about Excel to our forum: https://www.extendoffice.com/forum.html. You will get more Excel supports from our professional or other Excel fans.
  • To post as a guest, your comment is unpublished.
    Antonio · 3 years ago
    Gracias. Consulta: utilizando esta misma rutina, como podría enviar el correo a un correo específico dependiendo el valor de otra celda?
  • To post as a guest, your comment is unpublished.
    Jermaine · 3 years ago
    How to automate the email notification in VBA based on Date range, without having to see the pop up for security permission to allow VBA to send the email.