Home / How To / VBA Outlook: Insert Picture Signature Without Displaying Email

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.

<<Code Start>>

Private Function getHtmlSignature (SignatureName As String) As String

'Getting the outlook default path of the signature html file
Dim sFile As String
sFile = Environ("appdata") & "\Microsoft\Signatures\" & SignatureName & ".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 = SignatureName & "_files/"
'Getting the full path of the signature files
Dim htmlFullPath As String
htmlFullPath = Environ("appdata") & "/Microsoft/Signatures/" & SignatureName & "_files/"
'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
         .Send
End With

End Sub

<<Code End>>

0 comments

Leave a comment