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.
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
sSignature = .OpenTextFile(sFile, 1).readall
'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)
Below is how you create the email and call the above function to insert your signature
'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)
'adding subject and body
.Subject = "Subject goes here"
.To = "firstname.lastname@example.org"
.htmlBody = "Your email body text goes here"
'Now this is the code to add the signature.
.htmlBody = .htmlBody & vbCrLf & Sig
'Sending the email
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.
Great post. Thank you!
Leave a comment