Add signature to your automated emails

Tired of issues connected with email automation in Outlook application? Here is another one! In todays article we are going to get rid of it and learn how to add signature to your automated emails.

If You’ve ever tried to automate your correspondence in Outlook, You probably already did fight with that kind of problem. As far as I remember it was my main, maybe not the only one but main, issue – adding the signature in the end of newly created email using VBA. Now, knowing a few approaches to this topic, I decided to share my knowledge and describe in this article how to add signature to automated emails.

How to add signature in email using VBA?

For todays artcile I prepared 3 ways to do this. Sorted from the easiest to the most complex, but clear, approach.

1. Paste signature from prepared Word doc

This is the easiest way to get this done. In previous article I described how to paste the content of Word document easily, so having signature prepared already in doc file would be very convenient.

The same effect You could get prepared signature inside in code.

2. Create signature from email body

The second option is to get default signature from the email body and put that after the email content. Unfortunately this method has 2 downgrades.

The first disadvantage is that You need to remember to first Display the email and the second is that the final result is probably not that we expect to have.

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

OutMail.Display
Let Signature = OutMail.Body

With OutMail
    .Body = "Email content" & Signature
End With

3. Get signature from Outlook folder

Finally, the most complex approach is to get the signature from the .htm file, which is located in Outlook directory.

Firstly it finds the directory to the users Signatures folder, then looking for .htm file and as the last step is getting the content of this file into string variable.

Dim S As String
 S = Environ("appdata") & "\Microsoft\Signatures\"
 If Dir(S, vbDirectory) <> vbNullString Then S = S & Dir$(S & "*.htm") Else S = ""
 S = CreateObject("Scripting.FileSystemObject").GetFile(S).OpenAsTextStream(1, -2).ReadAll

The string variable is getting the content of the .htm file – singature with html code. It means that thanks to the method You keep whole formatting of your signature, in contrast to 2nd approach above.

Not the only solution

In this article I showed You 3 different solutions of how to add signature to automated emails using VBA. I hope it will help You in your macros. Choose the best solution for your needs and requirements. Sometimes even the simpliest is enough.

Tomasz Płociński

Author: Tomasz Płociński

I'm very advanced in VBA, Excel, also easily linking VBA with other Office applications (e.g. PowerPoint) and external applications (e.g. SAP). I take part also in RPA processes (WebQuery, DataCache, IBM Access Client Solutions) where I can also use my SQL basic skillset. I'm trying now to widen my knowledge into TypeScript/JavaScript direction.

Leave a Reply

Your email address will not be published. Required fields are marked *