vba 将带有图像的签名添加到邮件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25999201/
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
Add signature with images to the Mail
提问by Justin
I have a macro for Outlook where I can create a complete mail with an attachment but can not add a signature saved in my C drive (C:\Users\JustinG\AppData\Roaming\Microsoft\Signatures).
我有一个 Outlook 宏,我可以在其中创建带有附件的完整邮件,但无法添加保存在 C 驱动器中的签名 (C:\Users\JustinG\AppData\Roaming\Microsoft\Signatures)。
Signature types are .rtf
and .htm
with images.
签名类型是.rtf
和.htm
带有图像。
The following is the code:
以下是代码:
Sub Mail_Workbook_1()
Dim OutApp As Object
Dim Outmail As Object
Set OutApp = CreateObject("Outlook.Application")
Set Outmail = OutApp.CreateItem(0)
On Error Resume Next
' Change the mail address and subject in the macro before you run it.
With Outmail
.SentOnBehalfOfName = "[email protected]"
.To = "[email protected]"
.CC = ""
.BCC = ""
.Subject = "Presentation"
.Body = "Hi Team,"
.Attachments.add ("C:\Users\DurshetwarA\Desktop\Excel Examination_Master_V1.xlsx")
.display
''SendKeys ("%s")
End With
On Error GoTo 0
Set Outmail = Nothing
Set OutApp = Nothing
End Sub
回答by Adavid02
In the .htm file in the signatures directory you can edit the htm file. The pictures are stored as relative path and when you use the code it looses that path so if you use discrete path it will be able to find the pictures. so go into the file and look for any relative paths and make them discrete.
在签名目录中的 .htm 文件中,您可以编辑 htm 文件。图片存储为相对路径,当您使用代码时,它会丢失该路径,因此如果您使用离散路径,它将能够找到图片。所以进入文件并寻找任何相对路径并使它们离散。
"/Microsoft/Signatures/picturefile.jpg"
“/Microsoft/Signatures/picturefile.jpg”
change that to include the whole path
改变它以包括整个路径
"/root/user/blah blah../Microsoft/Signatures/picturefile.jpg"
“/root/user/blah blah ../Microsoft/Signatures/picturefile.jpg”
This solved the missing image problem for me.
这为我解决了丢失图像的问题。
回答by Yuvaraj Vaithinathan
Instead of .body use .htmlbody and design your message body in HTML. This is the only way of inserting image in your message. There is no specific option to insert signature
而不是 .body 使用 .htmlbody 并在 HTML 中设计您的消息正文。这是在您的消息中插入图像的唯一方法。没有插入签名的特定选项
回答by niton
Solution described hereby Ron de Bruin.
Ron de Bruin在此处描述的解决方案。
Sub Mail_Outlook_With_Signature_Html_2()
' Don't forget to copy the function GetBoiler in the module.
' Working in Office 2000-2013
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Dim SigString As String
Dim Signature As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strbody = "<H3><B>Dear Customer Ron de Bruin</B></H3>" & _
"Please visit this website to download the new version.<br>" & _
"Let me know if you have problems.<br>" & _
"<A HREF=""http://www.rondebruin.nl/tips.htm"">Ron's Excel Page</A>" & _
"<br><br><B>Thank you</B>"
'Change only Mysig.htm to the name of your signature
SigString = Environ("appdata") & _
"\Microsoft\Signatures\Mysig.htm"
If Dir(SigString) <> "" Then
Signature = GetBoiler(SigString)
Else
Signature = ""
End If
On Error Resume Next
With OutMail
.To = ""
.CC = ""
.BCC = ""
.Subject = "This is the Subject line"
.HTMLBody = strbody & "<br>" & Signature
.Send 'or use .Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
Function GetBoiler(ByVal sFile As String) As String
'Dick Kusleika
Dim fso As Object
Dim ts As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
GetBoiler = ts.readall
ts.Close
End Function