I made the codes below using this link as reference:
Dim chartPath As String
Dim messageA As String
Dim hyperlink As String
'Set chart path
chartPath = Environ("userprofile") & _
"\Documents\Chart " & Format(Now, "mm-dd-yyyy") & ".png"
'Set hyperlink
hyperlink = www.google.com
'Set message A
messageA = "<p style= 'font-family:arial;font-size:12'>" & "<b>" & Range("E17").Value & "</b>" & "<br>" & "<br>" & Range("E18").Value & "<br>" & "<br>" & Range("E19").Value & "<br>" & "<br>" & Range("E20").Value & " " & **"<b>" & "<u>" & "<a href =" & hyperlink & ">" & Range("E21").Value & "</a>" & "</u>" & "</b>"** & " " & Range("E22").Value & "<br>" & "<br>" & "<b>" & "<u>" & Range("E23").Value & "</u>" & "</b>" & "<br>" & "<br>" & "</p>"
With OutlookMailItem
.HTMLBody = messageA & "<img src ='" & chartPath & "'>"
End With
However, the text which contains hyperlink does not direct me to the website once click and I think, using string for this part is the problem. What could be the possible remedy for this
I was not able to run your code but I found that these 2 lines should have some changes:
'Set hyperlink
hyperlink = "www.google.com" 'Added ""
'Also you can set the value from a cell.
hyperlink = Cells(1,1).Value 'Get value from cell A1.
'Set message A - Removed **
messageA = "<p style= 'font-family:arial;font-size:12'>" & "<b>" & Range("E17").Value & "</b>" & "<br>" & "<br>" & Range("E18").Value & "<br>" & "<br>" & Range("E19").Value & "<br>" & "<br>" & Range("E20").Value & " " & "<b>" & "<u>" & "<a href =" & hyperlink & ">" & Range("E21").Value & "</a>" & "</u>" & "</b>" & " " & Range("E22").Value & "<br>" & "<br>" & "<b>" & "<u>" & Range("E23").Value & "</u>" & "</b>" & "<br>" & "<br>" & "</p>"
Please test your code again.
change this line hyperlink = www.google.com
to this: hyperlink = "http://www.google.com"
If your URL has spaces in it, those need to be replaced with %20
- This code will convert it for you:
hyperlink = Replace(hyperlink, " ", "%20")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.