It seems it is simple to add a html hyperlink to the body of an email using outlook. However I want to send a range of cells in the spreadsheet and a link to the file within the introduction. Or an easy way to click on the image created in the email and hyperlink to the file.
I have the following code but the strbody if I designated the introduction as HTMLintroduction, it does not allow it.
Any ideas?
Sub SendMail2()
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
'Dim Sendrng As Range
Set Sendrng = Worksheets("Dashboard").Range("A1:Q34")
If ActiveWorkbook.Path <> "" Then
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strbody = "<font size=""3"" face=""Calibri"">" & _
ActiveWorkbook.Name & "</B> is created.<br>" & _
"Click on this link to open the file : " & _
"<A HREF=""file://" & ActiveWorkbook.FullName & _
""">Link to the file</A>"
With Sendrng
ActiveWorkbook.EnvelopeVisible = True
With .Parent.MailEnvelope
.Introduction = strbody
On Error Resume Next
With ActiveSheet.MailEnvelope.Item
.To = "ac@uk.com"
.CC = ""
.BCC = ""
.Subject = ActiveWorkbook.Name
'.HTMLBody = strbody
.Display 'or use .Send
End With
End With
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
Else
MsgBox "Email not sent."
End If
End Sub
EDIT - ( http://vba-useful.blogspot.com/2014/01/send-html-email-with-embedded-images.html )
The above link details how to make a jpg out of the range and send that in the email.
I found some very similar code that seems to use a slightly different method. Perhaps it will work. It seems to bypass the Mail.Envelope method you are attempting. From Ron de Bruin's page. Unfortunately I can't test it on my current machine, so I hope it helps.
Sub Make_Outlook_Mail_With_File_Link()
'For Tips see: http://www.rondebruin.nl/win/winmail/Outlook/tips.htm
'Working in Excel 2000-2013
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
If ActiveWorkbook.Path <> "" Then
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strbody = "<font size=""3"" face=""Calibri"">" & _
"Colleagues,<br><br>" & _
"I want to inform you that the next sales Order :<br><B>" & _
ActiveWorkbook.Name & "</B> is created.<br>" & _
"Click on this link to open the file : " & _
"<A HREF=""file://" & ActiveWorkbook.FullName & _
""">Link to the file</A>" & _
"<br><br>Regards," & _
"<br><br>Account Management</font>"
On Error Resume Next
With OutMail
.To = "ron@debruin.nl"
.CC = ""
.BCC = ""
.Subject = ActiveWorkbook.Name
.HTMLBody = strbody
.Display 'or use .Send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
Else
MsgBox "The ActiveWorkbook does not have a path, Save the file first."
End If
End Sub
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.