vba excel 在介绍中使用带有 html 链接的父邮件信封发送电子邮件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27605773/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
vba excel send email using parent mailenvelope with html link in the introduction
提问by AC3
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.
使用 Outlook 在电子邮件正文中添加 html 超链接似乎很简单。但是,我想在电子表格中发送一系列单元格,并在介绍中发送指向该文件的链接。或者单击电子邮件中创建的图像和文件超链接的简单方法。
I have the following code but the strbody if I designated the introduction as HTMLintroduction, it does not allow it.
我有以下代码,但是如果我将介绍指定为 HTML 介绍,则 strbody 是不允许的。
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 = "[email protected]"
.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
回答by user3696061
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.
编辑- ( http://vba-useful.blogspot.com/2014/01/send-html-email-with-embedded-images.html)
上面的链接详细说明了如何使 jpg 超出范围并将其发送电子邮件。
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'spage. Unfortunately I can't test it on my current machine, so I hope it helps.
我发现了一些非常相似的代码,它们似乎使用了一种略有不同的方法。也许它会起作用。它似乎绕过了您正在尝试的 Mail.Envelope 方法。来自Ron de Bruin 的页面。不幸的是,我无法在我当前的机器上测试它,所以我希望它有所帮助。
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 = "[email protected]"
.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