0

I am trying to get my default signature and apply it to an email that I have being set up with a user form. I tried a few options including this one: How to add default signature in Outlook

but it doesn't seem to work...

Private Sub addUpdate_Click()
 Dim mailObj As MailItem
 Dim mailBody, signature As String
 Dim oMail, oApp As Object

newUser.Hide

Set oApp = CreateObject("Outlook.Application")
Set oMail = oApp.CreateItem(0)

With oMail
    .Display
End With
signature = oMail.body

Set mailObj = CreateItem(olMailItem)

mailBody = "<HTML><BODY><P>Hi " & firstName.Value & ",</P>" _
            & "<P>Thank you for your interest in the <STRONG>Metropolitan Sales</STRONG> website.</P>" _
            & "<P>Some of the features of the website include:</P>" _
            & "<UL><LI>Placing Orders</LI><LI>Order status & tracking</LI><LI>Detailed product information</LI>" _
            & "<LI>Specification sheets in PDF for all products</LI></UL>" _
            & "<P>These features can be accessed at:</P>" _
            & "<P><a href= 'http://www.metsales.com'>www.metsales.com</a>, then click on Catalog</p>" _
            & "<p><strong>Username : </strong>" & username.Value & "<br>" _
            & "<strong>Password  : </strong>" & password.Value & "</p>" _
            & "<p>Feel free to contact me should you have any questions.</p><br>" _
            & "<p>Thank you,</p>" & signature & "</body></html>"

With oMail
    .Recipients.add (email.Value)
    .Subject = "Metropolitan Sales Username and Password"
    .BodyFormat = olFormatHTML
    .HTMLBody = mailBody
    .Send
 End With
 Unload newUser
End Sub
Community
  • 1
  • 1
Adjit
  • 10,134
  • 12
  • 53
  • 98
  • 1
    You never set `signature` to anything. Look at the post you linked to and you'll see that when the email is first created `HTMLBody` **is** the signature. You store it in `signature` and then add it back at the end, as your current code tries to do. – Doug Glancy Sep 30 '13 at 22:18
  • Marked as duplicate of [How to add default signature in Outlook](http://stackoverflow.com/questions/8994116/how-to-add-default-signature-in-outlook). If there is a specific problem not covered in that post or by @DougGlancy's comment, please revise the question :) – David Zemens Oct 01 '13 at 01:06
  • 1
    Also note that you should properly `Dim mailiBody as String, signature As string` just to be safe. – David Zemens Oct 01 '13 at 01:08
  • So I managed to get the signature working (my form was showing while I tried to display the initial mail item and it caused an error) But now my issue, from what I can gather, is that because my body is an html body, and the signature is just a regular body, it isn't showing up the way I want it to. I reposted my updated code, but I have a few jpegs in my signature linking to twitter & facebook and stuff, but all that shows up now is HYPERLINK etc... and www.xyz.com – Adjit Oct 01 '13 at 14:04

1 Answers1

0

So I figured out how to do this... There is no need to create the oApp variable as this is being called from inside a running Outlook instance.

I also needed to set the BodyFormat to olFormatHTML

Set oMail = CreateItem(0)
With oMail
    .BodyFormat = olFormatHTML
    .Display
End With
signature = oMail.HTMLBody
Adjit
  • 10,134
  • 12
  • 53
  • 98