发送带有Excel宏签名的Outlook邮件时,正文不出现

时间:2018-11-18 18:20:54

标签: excel vba outlook

由于我是VBA的新手,所以我试图构建代码以通过带签名的Outlook发送电子邮件。但是,当我运行以下代码时,它仅向我显示签名(不显示正文)。

当我使用“ F8”进行检查时,可以清楚地看到我的身体出现,然后签名将其覆盖。如何解决此问题?

regexp

1 个答案:

答案 0 :(得分:1)

您需要将.body更改为.HTMLBody,请参考以下代码:

Option Explicit

Sub SendEmailwithsign()
Dim objoutApp As Object, objoutmail As Object
Dim strbody As String, strSig As String

Set objoutApp = CreateObject("outlook.Application")
Set objoutmail = objoutApp.CreateItem(0)
On Error Resume Next
With objoutmail
  .To = "emailAddress"
  .CC = ""
  .Subject = "Test mail"
   strSig = .Environ("appdata") & "Microsoft\Signatures\default.txt"
  strbody = "Hello"
  .HTMLBody = "<p>"+ strbody  +"</p>" & strSig     'with this step Body part does not appear but only the signature'
  .Recipients.ResolveAll
  .Display                 'body appears until this point'



  End With
   On Error GoTo 0
   Set objoutmail = Nothing
   Set objoutApp = Nothing

End Sub

引用来自:

VBA Signature on Email with HTMLBody