Loncat ke daftar isi utama

Bagaimana cara mengirim email dari Excel dengan hyperlink di badan email?

Pernahkah Anda mencoba mengirim email dengan kode VBA di Excel? Dan bagaimana cara menambahkan hyperlink ke teks isi email saat mengirim email? Artikel ini akan membantu menyelesaikan masalah ini.

Masukkan hyperlink ke badan email dengan kode VBA


Masukkan hyperlink ke badan email dengan kode VBA

Kode VBA di bawah ini dapat membantu mengirim email dari Excel dan memasukkan hyperlink tertentu di badan email. Silakan lakukan sebagai berikut.

1. Luncurkan buku kerja Anda, tekan lain + F11 kunci untuk membuka Microsoft Visual Basic untuk Aplikasi jendela.

2. Dalam Microsoft Visual Basic untuk Aplikasi window, klik Menyisipkan > Modul, lalu salin kode VBA di bawah ini ke editor Modul.

Kode VBA: Masukkan hyperlink ke badan email

Sub EmailHyperlink()
'updated by Extendoffice 20190815
Dim xOtl As Object
Dim xOtlMail As Object
Dim xStrBody As String
    xStrBody = "Hi there:" & "<br>" _
              & "Please click " & "<a href=" & "http://www.extendoffice.com"">Here</a> to open the page" & "<br>" _
              & "Thank you."
    On Error Resume Next
    Set xOtl = CreateObject("Outlook.Application")
    Set xOtlMail = xOtl.CreateItem(olMailItem)
    With xOtlMail
        .To = "Email Address"
        .CC = "Email Address "
        .BCC = " Email Address "
        .Subject = "Subject line"
        .HTMLBody = .HTMLBody & xStrBody
        .Display
    End With
    Set xOtl = Nothing
    Set xOtlMail = Nothing
End Sub

Catatan:

  • Harap ubah konten tubuh dan hyperlink di xStrBody line.
  • Ganti "Alamat email" dalam . Untuk, .DC dan.BCC baris dengan alamat email sebenarnya yang akan Anda kirimi email. Jika Anda tidak memerlukan baris CC dan BCC, hapus saja dari seluruh kode, atau tambahkan satu kutipan sebelum baris, seperti 'CC = ”Alamat Email”.
  • Ganti "Garis subjek" dalam .Subyek sejalan dengan subjek email Anda sendiri.

3. tekan F5 kunci untuk menjalankan kode. Kemudian email dibuat dengan bidang dan badan tertentu dengan hyperlink terdaftar di dalamnya, klik tombol Kirim untuk mengirimnya.


Terkait artikel

Kirim email secara otomatis berdasarkan nilai sel di Excel
Misalkan Anda ingin mengirim email melalui Outlook ke penerima tertentu berdasarkan nilai sel tertentu di Excel. Misalnya, jika nilai sel D7 di lembar kerja lebih besar dari 200, maka email dibuat secara otomatis. Artikel ini memperkenalkan metode VBA bagi Anda untuk menyelesaikan masalah ini dengan cepat.

Kirim email jika tombol diklik di Excel
Misalkan Anda perlu mengirim email melalui Outlook dengan mengklik tombol di lembar kerja Excel, bagaimana Anda bisa melakukannya? Artikel ini akan memperkenalkan metode VBA untuk mencapainya secara detail.

Kirim email jika tanggal jatuh tempo sudah terpenuhi di Excel
Misalkan tanggal jatuh tempo di kolom C kurang dari atau sama dengan 7 hari (tanggal sekarang 2017/9/13), maka kirimkan email reminder ke penerima yang ditentukan di kolom A dengan konten tertentu di kolom B. Bagaimana cara mencapainya? Metode dalam artikel ini dapat membantu Anda.

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 (17)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hallo, das läuft soweit sehr gut.
Ich möchte jedoch, das ein Link generiert wird zu der Datei mit dem Dateinamen der aktuell geöffneten Datei. ThisWorkbook.FullName oder so ähnlich.
Wie würde der Code dann aussehen???

Vielen Dank
This comment was minimized by the moderator on the site
Does anyone know how to combine/ add this with a code I am already using to send an email? The one bellow?

Public Sub CheckAndSendMail()
'Updated by Extendoffice 2018/11/22
Dim xRgDate As Range
Dim xRgSend As Range
Dim xRgText As Range
Dim xRgDone As Range
Dim xOutApp As Object
Dim xMailItem As Object
Dim xLastRow As Long
Dim vbCrLf As String
Dim xMailBody As String
Dim xRgDateVal As String
Dim xRgSendVal As String
Dim xMailSubject As String
Dim i As Long
On Error Resume Next
Set xRgDate = Application.InputBox("Please select the due date column:", "KuTools For Excel", , , , , , 8)
If xRgDate Is Nothing Then Exit Sub
Set xRgSend = Application.InputBox("Please select the recipients?email column:", "KuTools For Excel", , , , , , 8)
If xRgSend Is Nothing Then Exit Sub
Set xRgText = Application.InputBox("Select the column with reminded content in your email:", "KuTools For Excel", , , , , , 8)
If xRgText Is Nothing Then Exit Sub
xLastRow = xRgDate.Rows.count
Set xRgDate = xRgDate(1)
Set xRgSend = xRgSend(1)
Set xRgText = xRgText(1)
Set xOutApp = CreateObject("Outlook.Application")
For i = 1 To xLastRow
xRgDateVal = ""
xRgDateVal = xRgDate.Offset(i - 1).Value
If xRgDateVal <> "" Then
If CDate(xRgDateVal) - Date <= 7 And CDate(xRgDateVal) - Date > 0 Then
xRgSendVal = xRgSend.Offset(i - 1).Value
xMailSubject = xRgText.Offset(i - 1).Value & " on " & xRgDateVal
vbCrLf = "<br><br>"
xMailBody = "<HTML><BODY>"
xMailBody = xMailBody & "Dear " & xRgSendVal & vbCrLf
xMailBody = xMailBody & "Text : " & xRgText.Offset(i - 1).Value & vbCrLf
xMailBody = xMailBody & "</BODY></HTML>"
Set xMailItem = xOutApp.CreateItem(0)
With xMailItem
.Subject = xMailSubject
.To = xRgSendVal
.HTMLBody = xMailBody
.Display
'.Send
End With
Set xMailItem = Nothing
End If
End If
Next
Set xOutApp = Nothing
End Sub
This comment was minimized by the moderator on the site
Hi Crystal, no problem, thank you anyway.
This comment was minimized by the moderator on the site
Hallo,

wie würde der Code aussehen, wenn im Email-Text genau der Link zu der Datei stehen soll, aus der heraus die Email generiert wurde? Nach dem Motto: "Gehe zu Datei xxx (als Link) und trage dort etwas ein.

Vielen Dank und schöne Grüße
Florian
This comment was minimized by the moderator on the site
Hi Florian Mußler,
Please change the following lines
 xStrBody = "Hi there:" & "<br>" _
              & "Please click " & "<a href="/ & "http://www.extendoffice.com"">Here</a> to open the page" & "<br>" _
              & "Thank you."

to
 xStrBody = "Hi there:" & "<br>" _
              & "Go to the file " & "<a href="/ & "I:\Work\Crystal\2023\Sales Report.xlsx"">Sales Report</a> and enter the content there" & "<br>" _
              & "Thank you."

where "I:\Work\Crystal\2023\Sales Report.xlsx" is the path of the file.
This comment was minimized by the moderator on the site
Thank you for your help. This already works great. Do you know how to write the code, if I have to extract the file address out of a cell?
This comment was minimized by the moderator on the site
Hi crystal,

thank you very much for your reply. This is what I came up with at first. The thing is, that the file we are talking about is based on a template. That means, that the file name is changed to an individual file name, that is always different. So the file name (link) in the code should be a variable, always leading to this exacte file (in which the code is running).

I hope I could describe this correctly, so you understand.

Thank you.
This comment was minimized by the moderator on the site
Hi Florian,

I understand what you mean now. But I'm sorry I don't know how to create a hyperlink to a workbook that contains a variable name.
This comment was minimized by the moderator on the site
Bonjour,
Merci pour cette procédure.
Comment puis-je remplacer le lien (qui est fixe) par un lien variable ?
...
Dim xStrBody As String
Dim Lien As String
Lien = "https://www.cyclodetente.be/"

xStrBody = "Hi there:" & "<br>" _
& "Please click " & "<a href="/ & "http://www.extendoffice.com"">Here</a> to open the page" & "<br>" _
& "Thank you."
...
Donc, remplacer "http://www.extendoffice.com" par la variable "Lien"

Un tout grand merci pour le retour,
This comment was minimized by the moderator on the site
Hi Christian,

Sorry I don't quite understand what you mean. For clarity, please attach a sample file or a screenshot with your data and desired results.
This comment was minimized by the moderator on the site
my link isn't clickable and I'm not sure why.

"Please Print <a href="/"http://codes" & Range("JobNumber") & "&ReportId=1"">" & "PhoneCodes</a>"

The link appears but I have to right-click on the email for it to open up. Any suggestions? Also, I don't really know much about VBA. This is something new I'm learning on my own.
This comment was minimized by the moderator on the site
Hi Maryanne,
By default, when you composing an email, hyperlinks are opened by clicking with pressing or holding the Ctrl key.
If you want to open a hyperlink with one click only, please turn off this function as follows.
1. In your Outlook, click File > Options.
2. In the Outlook Options dialog box, click Mail in the left pane, and then click the Editor Options button in the Compose Messages section;
3. In the Editor Options dialog box, click Advanced in the left pane, and then uncheck the Use CTRL + Click to follow hyperlink checkbox. See screenshot:
https://www.extendoffice.com/images/stories/comments/comment-picture-zxm/hyperlink.png
This comment was minimized by the moderator on the site
please i need help it doesnt work when the link have spaces in itfor ex file path MsgBox "C:\Users\Desktop\fs caché\Fusion fichier\TENDERING.xlsm"
xstrbody = "Request for an approval, <br> You can access to the file from " & "<a href= " & link & ">here</a>"
the link will be in this case : C:\Users\Desktop\fsany idea?
This comment was minimized by the moderator on the site
You can use: xstrbody = "Request for an approval, <br> You can access to the file from " & "<a href="/"" & link & """> here</a >"
This comment was minimized by the moderator on the site
this code is great, but how to send the current excel sheet in the email?
This comment was minimized by the moderator on the site
you use "xStrBody" part in your existing code, other search Excel to outlook email code online and use "xStrBody" this part.
This comment was minimized by the moderator on the site
you can use "xStrBody" part in other email code, which you are using now. otherwise search "excel to outlook email code".
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations