我找到了此代码,但不包含签名。在我阅读的所有资源中,我都无法提出解决方案。
Public Function Email_Test()
Dim MyOutlook As Outlook.Application
Dim MyMail As Outlook.MailItem
Dim objOutlook As Object
Dim Attach As String
Set MyOutlook = New Outlook.Application
Set MyMail = MyOutlook.CreateItem(olMailItem)
MyMail.To = "[email protected]" '**put in reference to form
'MyMail.CC = MailList("Copy To")
MyMail.Subject = "This Is A Test Email" '**put in reference for subject
MyMail.Body = "Hi," & vbNewLine & vbNewLine & "See attached."
'MyMail.Send
MyMail.Display
Set MyMail = Nothing
Set MyOutlook = Nothing
End Function
Outlook是HTML应用程序。您将需要使用.HTMLBody,并且在可能要输入的任何文本的末尾确保包含.HTMLBody = "text"& .HTMLBody
。此.HTMLBody
必须在电子邮件的任何正文部分的末尾,以使签名自动出现。我会避免尝试使用多种正文类型,而在为Outlook编码时只坚持使用HTML。在为Outlook编码时,请使用@shmicah链接在注释中提供的常规格式。如果您的签名没有出现在您想要的位置,那么请为每行添加下来。
仅在调用Display之前未修改邮件正文的情况下,MailItem.Display
添加签名。首先呼叫Display,然后再呼叫现有的邮件正文(将包括签名)与您自己的数据。并且,如果要保留格式,则需要使用HTMLBody
属性,而不是纯文本Body
。但这意味着您必须适当地合并两个HTML字符串-您不能仅将它们串联。
这是我用来在邮件上附加签名的代码示例。
Sub Email()
'Working in 2000-2010
'This example send the last saved version of the Activeworkbook
Dim OutApp As Object
Dim OutMail As Object
Dim Path As String: Path = Sheet10.Range("H6").Text & " " & Sheet10.Range("I6").Text
Dim strbody As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strbody = "Attached updated Stock."
On Error Resume Next
With OutMail
.Display
.To = "[email protected]"
.CC = ""
.BCC = ""
.Subject = "Fruits Stock " & Path
.HTMLBody = strbody & .HTMLBody
.Attachments.Add ActiveWorkbook.FullName
'You can add other files also like this
'.Attachments.Add ("C:\test.txt")
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub