VBA Outlook: Insert Picture Signature Without Displaying Email

Insert Picture Signature Without Email Display

I have been searching the internet for a VBA code to insert my picture signature to my email and found many posts stating that to insert a picture signature you will have to display the email which when used, had a dramatic impact on the speed of the program. It increased the time by more than 20x as measured on my laptop.

After many trials and more errors, I figured out that to Insert Picture Signature without having to Display the email you must change the relative paths of the signature html code to absolute path. This is what the below function does.

Change red words to your own settings.

<<Code Start>>

Private Function getHtmlSignature (SignatureName As String) As String

'Getting the outlook default path of the signature html file
Dim sFile As String
Dim sSig as string
sSig = SignatureName 
sFile = Environ("appdata") & "\Microsoft\Signatures\" & sSig & ".htm"
'Reading the signature HTML file in a string variable
Dim sSignature As String
With CreateObject("Scripting.FileSystemObject")
sSignature = .OpenTextFile(sFile, 1).readall
End With
'Getting the relative path as written in the signature html file
Dim htmlRelPath As String
htmlRelPath = sSig & "_files/"
'Getting the full path of the signature files and replacing any space with %20
Dim htmlFullPath As String
htmlFullPath = VBA.Replace("file:///" & Environ("appdata") & "/Microsoft/Signatures/" & sSig & "_files/", " ", "%20")
'replacing the backward slash \ with a forward Slash / in the path string
htmlFullPath = VBA.Replace(htmlFullPath, "\", "/")
'replacing the relative path with full path in the signature variable
getHtmlSignature = VBA.Replace(sSignature, htmlRelPath, htmlFullPath)

End Function

<<Code End>>

Below is how you create the email and call the above function to insert your signature

<<Code Start>>

Sub MainCode()

'Getting the Signature HTML code in a string variable using the above function
Dim Sig as string
Sig = getHtmlSignature(SignatureName)
'Creating Outlook object
Dim olApp As Object
Set olApp = CreateObject("Outlook.Application")
'Creating the email
Dim oMail As Object
Set oMail = olApp.createitem(0)
With oMail
         'adding subject and body
         .Subject = "Subject goes here"
         .To = "info@paracons.ca"
         .htmlBody = "Your email body text goes here"
         'Now this is the code to add the signature.
         .htmlBody = .htmlBody & vbCrLf & Sig
         'Sending the email
End With

End Sub

<<Code End>>


  • Martin

    The post appeared to solve my problem of adding a signature with VBA. However, unfortunately it doesn’t appear to work… the image in my signature is visible on the email in my sent items (on my machine). However, the signature image is not visible on for email recipients. It appears that the unlike the text and hyperlinks in my signature, the image is referenced in… It displays on my PC because the image is in my outlook signatures folder. Not too sure if this is a VBA error, please can you assist. Many thanks.

  • James

    Great post. Thank you!

Leave a comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.