Reputation: 57
Since I am new to the VBA I am trying to structure a code to send email through outlook with the signature.But when I run the below code it displays me only the signature (body does not appear).
When I use "F8" and check it can be clearly seen that my body appears then signature overwrites it.How do I fix this?
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 = "[email protected]"
.CC = ""
.Subject = "Test mail"
.Recipients.ResolveAll
.Display 'body appears until this point'
strSig = .Environ("appdata") & "Microsoft\Signatures\bbbb.txt"
strbody = "Hello"
.body = strbody & strSig 'with this step Body part does not appear but only the signature'
End With
On Error GoTo 0
Set objoutmail = Nothing
Set objoutApp = Nothing
End Sub
Upvotes: 0
Views: 739
Reputation: 884
You need to change .body
to .HTMLBody
, please refer to the below code:
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
Reference from:
VBA Signature on Email with HTMLBody
Upvotes: 1