Skip i'r prif gynnwys

Sut i anfon e-bost gan Excel gyda hyperddolen yn y corff e-bost?

Ydych chi erioed wedi ceisio anfon e-bost gyda chod VBA yn Excel? A sut i ychwanegu hypergysylltiadau i destun corff yr e-bost wrth anfon e-bost? Bydd yr erthygl hon yn helpu i ddatrys y broblem hon.

Mewnosod hyperddolen yn y corff e-bost gyda chod VBA


Mewnosod hyperddolen yn y corff e-bost gyda chod VBA

Gall y cod VBA isod helpu i anfon e-bost gan Excel a mewnosod hyperddolen benodol yn y corff e-bost. Gwnewch fel a ganlyn.

1. Lansio'ch llyfr gwaith, pwyswch y Alt + F11 allweddi i agor y Microsoft Visual Basic ar gyfer Ceisiadau ffenestr.

2. Yn y Microsoft Visual Basic ar gyfer Ceisiadau ffenestr, cliciwch Mewnosod > Modiwl, ac yna copïwch y cod VBA isod i olygydd y Modiwl.

Cod VBA: Mewnosod hyperddolen yn y corff e-bost

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

Nodiadau:

  • Newid cynnwys y corff a'r hyperddolen yn y xStrBody llinell.
  • Amnewid y “Cyfeiriad e-bost"Yn y . I, .DC a.BCC llinellau gyda'r cyfeiriadau e-bost gwirioneddol y byddwch yn anfon e-bost atynt. Os nad oes angen y llinellau CC a BCC arnoch, tynnwch nhw o'r cod cyfan, neu ychwanegwch ddyfynbris sengl cyn y llinellau, fel 'CC = "Cyfeiriad E-bost".
  • Amnewid y “Llinell bwnc"Yn y .Sbject yn unol â'ch pwnc e-bost eich hun.

3. Gwasgwch y F5 allwedd i redeg y cod. Yna mae'r e-bost yn cael ei greu gyda meysydd a chorff penodol gyda hyperddolen wedi'i rhestru y tu mewn, cliciwch y botwm Anfon i'w anfon.


Erthyglau perthnasol

Anfon e-bost yn awtomatig yn seiliedig ar werth celloedd yn Excel
Gan dybio eich bod am anfon e-bost trwy Outlook at dderbynnydd penodol yn seiliedig ar werth celloedd penodol yn Excel. Er enghraifft, pan fydd gwerth cell D7 mewn taflen waith yn fwy na 200, yna crëir e-bost yn awtomatig. Mae'r erthygl hon yn cyflwyno dull VBA i chi ddatrys y broblem hon yn gyflym.

Anfon e-bost os yw'r botwm wedi'i glicio yn Excel
Gan dybio bod angen i chi anfon e-bost trwy Outlook trwy glicio botwm yn nhaflen waith Excel, sut allwch chi wneud? Bydd yr erthygl hon yn cyflwyno dull VBA i'w gyflawni mewn manylion.

Anfon e-bost os yw'r dyddiad dyledus wedi'i fodloni yn Excel
Gan dybio bod y dyddiad dyledus yng ngholofn C yn llai na neu'n hafal i 7 diwrnod (y dyddiad cyfredol yw 2017/9/13), yna anfonwch nodyn atgoffa e-bost at y derbynnydd penodedig yng ngholofn A gyda chynnwys penodol yng ngholofn B. Sut i'w gyflawni? Gall y dull yn yr erthygl hon wneud ffafr i chi.

Offer Cynhyrchiant Swyddfa Gorau

🤖 Kutools AI Aide: Chwyldro dadansoddi data yn seiliedig ar: Cyflawniad Deallus   |  Cynhyrchu Cod  |  Creu Fformiwlâu Personol  |  Dadansoddi Data a Chynhyrchu Siartiau  |  Invoke Swyddogaethau Kutools...
Nodweddion Poblogaidd: Darganfod, Amlygu neu Adnabod Dyblygiadau   |  Dileu Rhesi Gwag   |  Cyfuno Colofnau neu Gelloedd heb Colli Data   |   Rownd heb Fformiwla ...
Super-edrych: VLookup Meini Prawf Lluosog    VLookup Gwerth Lluosog  |   VLookup Ar Draws Taflenni Lluosog   |   Edrych Niwlog ....
Rhestr gwympo Uwch: Creu Rhestr Gollwng yn Gyflym   |  Rhestr Gollwng Dibynnol   |  Rhestr Gollwng Aml-ddewis ....
Rheolwr Colofn: Ychwanegu Nifer Penodol o Golofnau  |  Symud Colofnau  |  Toglo Statws Gwelededd Colofnau Cudd  |  Cymharwch Ystodau a Cholofnau ...
Nodweddion dan Sylw: Ffocws ar y Grid   |  Golwg Dylunio   |   Bar Fformiwla Mawr    Rheolwr Llyfr Gwaith a Thaflen   |  Llyfrgell Adnoddau (Testun Auto)   |  Dewiswr Dyddiad   |  Cyfuno Taflenni Gwaith   |  Amgryptio/Dadgryptio Celloedd    Anfon E-byst trwy Restr   |  Hidlo Super   |   Hidlo Arbennig (hidlo mewn print trwm/italig/strikethrough...) ...
15 Set Offer Gorau12 Testun offer (Ychwanegu Testun, Dileu Cymeriadau,...)   |   50 + Siart Mathau (Siart Gantt,...)   |   40+ Ymarferol Fformiwlâu (Cyfrifwch oedran yn seiliedig ar ben-blwydd,...)   |   19 mewnosod offer (Mewnosod Cod QR, Mewnosod Llun o'r Llwybr,...)   |   12 Trosi offer (Rhifau i Eiriau, Trosi arian cyfred,...)   |   7 Uno a Hollti offer (Rhesi Cyfuno Uwch, Celloedd Hollt,...)   |   ... a mwy

Supercharge Eich Sgiliau Excel gyda Kutools ar gyfer Excel, a Phrofiad Effeithlonrwydd Fel Erioed Erioed. Kutools ar gyfer Excel Yn Cynnig Dros 300 o Nodweddion Uwch i Hybu Cynhyrchiant ac Arbed Amser.  Cliciwch Yma i Gael Y Nodwedd Sydd Ei Angen Y Mwyaf...

Disgrifiad


Mae Office Tab yn dod â rhyngwyneb Tabbed i Office, ac yn Gwneud Eich Gwaith yn Haws o lawer

  • Galluogi golygu a darllen tabbed yn Word, Excel, PowerPoint, Cyhoeddwr, Mynediad, Visio a Phrosiect.
  • Agor a chreu dogfennau lluosog mewn tabiau newydd o'r un ffenestr, yn hytrach nag mewn ffenestri newydd.
  • Yn cynyddu eich cynhyrchiant 50%, ac yn lleihau cannoedd o gliciau llygoden i chi bob dydd!
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