VBA Signature on Email with HTMLBody
VBA Signature on Email with HTMLBody
So i got the following from How to add default signature in Outlook. However, i keep getting an error "Application-defined or object-defined error" where the signature variable is set. Plz HALP.
Dim OApp As Object, OMail As Object, signature As String
Set OApp = CreateObject("Outlook.Application")
Set OMail = OApp.CreateItem(0)
With OMail
.Display
End With
signature = OMail.body
With OMail
'.To = "someone@somedomain.com"
'.Subject = "Type your email subject here"
'.Attachments.Add
.body = "Add body text here" & vbNewLine & signature
'.Send
End With
Set OMail = Nothing
Set OApp = Nothing
I know i could get the signature from the C:Users...Signatures folder. However at work, we all use virtual desktops and the permissions there are a tad janky.
.Body
.HTMLBody
The signature is just simple text, no pictures or anything crazy. I could go with either, but i'd prefer to use
.HTMLBody
. But i literally copied and pasted the above code, and still get the error. Im just trying to find a starting point and cant even get there.– TideRunner
1 hour ago
.HTMLBody
And if you step through with F8 you can see the signature once the email is displayed?
– BigBen
1 hour ago
i cant even step in it throws the error before i can even try. if i just avoid using the signature variable, it is there.
– TideRunner
1 hour ago
1 Answer
1
Your signature has to be declared as a variant.
Dim OApp As Object
Dim OMail As Object
Dim Signature As Variant
Set OApp = CreateObject("Outlook.Application")
Set OMail = OutApp.CreateItem(0)
On Error Resume Next
With OMail
'Capture signature block.
.Display
Signature = .HTMLBody
'.To = Recipients
'.CC = CarbonCopy
.Subject = "Subject"
.HTMLBody = "<p>Add Body Here.</p>" & Signature
.Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
so with this, i don't get an error, but i only get a signature. like it's overwriting the body.
– TideRunner
31 mins ago
Try adding HTML tags. The code above has been edited.
– pondersome
24 mins ago
that worked! thx
– TideRunner
16 mins ago
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Are you using
.Body
or.HTMLBody
? How complex is your signature - is there an embedded picture, for example?– BigBen
1 hour ago