• Outlook User
  • New Outlook app
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
  • Developer
  • Microsoft 365 Admin
    • Common Problems
    • Microsoft 365
    • Outlook BCM
    • Utilities & Addins

Insert or change an Outlook signature using VBA

Slipstick Systems

› Developer › Code Samples › Insert or change an Outlook signature using VBA

Last reviewed on June 7, 2017     13 Comments

The macros in this article will insert a specific signature file into a message.

The first macro creates a new message with a specific signature file inserted. (You can use this method to insert any HTML file into a message.)

create a new message with a signature

Public Sub CreateMessageSignature()
Dim objMsg As MailItem
Dim strBuffer As String
enviro = CStr(Environ("appdata"))
Debug.Print enviro
Set objFSO = CreateObject("Scripting.FileSystemObject")

' Edit the signature file name on the following line
strSigFilePath = enviro & "\Microsoft\Signatures\"
Debug.Print strSigFilePath
Set objSignatureFile = objFSO.OpenTextFile(strSigFilePath & "My Sig.htm")
strBuffer = objSignatureFile.ReadAll
objSignatureFile.Close

Set objMsg = Application.CreateItem(olMailItem)
With objMsg
  .Subject = "Subject goes here"
  .HTMLBody = "<p>Something here.</p><p> </p>" & strBuffer
  .Display
End With
  
End Sub

Change Signatures

If you need to change a signature in a reply, you will need to remove the signature that was added automatically and insert a new one. If you are creating a new message or not keeping the message body, you can insert an HTML signature directly into .HTMLBody.
reply with a new signature

This macro removes the default signature and adds a new one. After using this macro, the signature bookmark is removed and you will not be able to change the signature automatically. You will be able to insert another signature manually.

You will need to set a reference to the Microsoft Word Object Library in Tools, References.

Sub ReplywithChangeSig()
Dim Item As Outlook.MailItem
Dim strBuffer As String
enviro = CStr(Environ("appdata"))

Set objFSO = CreateObject("Scripting.FileSystemObject")
' Edit the signature file name on the following line
strSigFilePath = enviro & "\Microsoft\Signatures\"
Debug.Print strSigFilePath
Set objSignatureFile = objFSO.OpenTextFile(strSigFilePath & "My Sig.htm")
strBuffer = objSignatureFile.ReadAll
objSignatureFile.Close

Set Item = Application.ActiveExplorer.Selection.Item(1)

Dim olInspector As Outlook.Inspector
Dim olDocument As Word.Document
Dim olSelection As Word.Selection

Set myreply = Item.Reply
myreply.Display

Set olInspector = myreply.GetInspector
Set olDocument = olInspector.WordEditor
Set olSelection = olDocument.Application.Selection

Set oBookmark = olDocument.Bookmarks("_MailAutoSig")

If Not oBookmark Is Nothing Then
    oBookmark.Select
    olDocument.Windows(1).Selection.Delete
End If

  With olSelection.Borders(wdBorderBottom)
    .LineStyle = wdLineStyleSingle
    .LineWidth = wdLineWidth025pt
    .Color = wdColorGray10
  End With

myreply.HTMLBody = "<p>&nbsp;</p>" & strBuffer & myreply.HTMLBody
olSelection.MoveStart

' uncomment to send
 'myReply.Send

End Sub

Sample macros that insert stationary files into new messages are at

Create a New Message using an HTML File or Stationery

How to use the Macro

First: You will need macro security set to low during testing.

To check your macro security in Outlook 2010 and newer, go to File, Options, Trust Center and open Trust Center Settings, and change the Macro Settings. In Outlook 2007 and older, it’s at Tools, Macro Security. If Outlook tells you it needs to be restarted, close and reopen Outlook. Note: after you test the macro and see that it works, you can either leave macro security set to low or sign the macro.

Now open the VBA Editor by pressing Alt+F11 on your keyboard.

To put the code in a module:

  1. Right click on Project1 and choose Insert > Module
  2. Copy and paste the macro into the new module.
  3. Set a reference to the Word Object Model in the VBA editor's Tools, References dialog.
    Reference the Word object model in Outlook's VBA Editor

More information as well as screenshots are at How to use the VBA Editor.

Insert or change an Outlook signature using VBA was last modified: June 7th, 2017 by Diane Poremsky

Related Posts:

  • Remove Email Signature from Message using VBA
  • Run a script rule: Reply to a message
  • Create a New Message using an HTML File or Stationery
  • Create a custom Send to... shortcut

About Diane Poremsky

A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

Subscribe
Notify of
13 Comments
newest
oldest most voted
Inline Feedbacks
View all comments

Brett
July 22, 2022 9:57 am

Hi Diane, I'm not super familiar with coding, but I wonder if you might be able to advise me on a similar code I found and pasted into a Excel doc I use: Sub savesheet() Dim Name As String &nbsp; &nbsp; Application.ScreenUpdating = False &nbsp; &nbsp; Application.DisplayAlerts = False &nbsp; &nbsp; ActiveWorkbook.Save &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; Name = "Grocery &amp; Dairy 3rd Shift ABSENTEE BLANK (1ST SHIFT)" &amp; ".xlsm" &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; ActiveWorkbook.SaveAs Filename:=Name &nbsp; &nbsp; Application.DisplayAlerts = True &nbsp; &nbsp; Application.ScreenUpdating = True End Sub Sub EmailWBAttached() Dim OutApp As Object Dim OutMail As Object Set OutApp = CreateObject("Outlook.Application") Set OutMail = OutApp.CreateItem(0) On Error Resume Next &nbsp; &nbsp; With OutMail &nbsp; &nbsp; &nbsp; &nbsp; .To = "email@test.com"&nbsp; &nbsp; &nbsp; &nbsp; '&lt;-- enter email addresses here. Multiple emails separate by comma &nbsp; &nbsp; &nbsp; &nbsp; .CC = "" &nbsp; &nbsp; &nbsp; &nbsp; .BCC = "" &nbsp; &nbsp; &nbsp; &nbsp; .Subject = "3rd Shift Attendance: " &amp; Format(Now(), "mm.dd.yy")&nbsp; '&lt;-- enter subject here &nbsp; &nbsp; &nbsp; &nbsp; .Body = "Attached is the attendance sheet or revision to 3rd Shift Grocery &amp; Dairy."&nbsp; &nbsp; &nbsp; '&lt;-- enter message body here &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .Attachments.Add Application.ActiveWorkbook.FullName… Read more »

Last edited 3 years ago by Brett
0
0
Reply
Juan Ruiz
April 10, 2021 11:03 pm

Hi Diane,

This is a great script. Best I've seen about adding the signature.

I tried the add signature (in Excel) and works with the exception of three missing images that are present when email is manually created in Outlook. Any suggestions?

1
0
Reply
Branislav Krljanac
February 23, 2021 4:32 am

Hi there,

can anyone tell me how to enter any text (e.g. Greetings.....plus signature)
into an existing mail that has no body text yet, but it has already recipient
selected.
So the macro should not create an email.
Instead the text should be added into the existing message.
Name of the recipient should be added into the body, like Dear & Recipient...

Thanks a lot in advance.

Branislav

0
0
Reply
Carl Stephens
Reply to  Branislav Krljanac
December 13, 2022 7:31 pm

strSignature = .HTMLBody 'the signature is there, so get it before overwriting the body
    .HTMLBody = "Hello " & Sheets("OT").Range("L2").Value & "," & strSignature '< concatenate the signature to the end

This basically uses a greeting ("Hello") and looks up the persons name on a spreadsheet and adds the signature afterwards.

0
0
Reply
Reuben Geoffrey Dayal
September 14, 2018 5:20 am

Hi Diane,

Can you guide me on how can I use the text before the current email's auto signature bookmark? I am trying to search for a keyword "follow up" in my current reply, to trigger a macro for setting a reminder. It is important to only search the text in the current reply (before the auto signature) to verify whether the keyword exists, and only then trigger the macro else, do nothing.

Thank you in advance.

0
0
Reply
rino19ny
November 9, 2017 10:14 am

was looking for something like this and found a VB script instead that creates new signatures and makes it the default. pretty basic but you can insert company logo. is it permitted to post here the code? the original author is still there mentioned in the code.

0
0
Reply
Diane Poremsky
Author
Reply to  rino19ny
November 16, 2017 10:06 pm

Yes, you can post it here.

0
0
Reply
Oliv
November 2, 2017 5:14 pm

Hi Diane,
Please take a look at my code that uses ribbon and UIAUTOMATION

https://www.developpez.net/forums/blogs/191381-oliv/b4076/inserer-signature-lemail-actif-outlook-2016/

0
0
Reply
Diane Poremsky
Author
Reply to  Oliv
November 3, 2017 9:51 am

I wouldn't say its any better than reading the signature file and inserting - it's basically sendkeys. (If Outlook supported 'screenupdating = false' it would be better - i wouldn't have to watch the signature selector expand and the mouse move.)

As a demo for UIAUTOMATION, its good - and could be very useful to do other things in Outlook.

0
0
Reply
Oliv
Reply to  Diane Poremsky
November 3, 2017 12:12 pm

The behavior is different if we run the macro from Excel, in this case we can just use DoDefaultAction, but not when we run it from OUTLOOK !

it is useful if the signature contains images.

Public Sub CreateMessageSignatureWithImage()
    Dim objMsg As MailItem
    Dim strBuffer As String
    Dim enviro, objFSO, strSigFilePath, objSignatureFile
    Dim strAtt, SplitAtt, EmbAtt As Attachment
    enviro = CStr(Environ("appdata"))
    Debug.Print enviro
    Set objFSO = CreateObject("Scripting.FileSystemObject")

    ' Edit the signature file name on the following line
    strSigFilePath = enviro &amp; "\Microsoft\Signatures\"
    Debug.Print strSigFilePath
    Set objSignatureFile = objFSO.OpenTextFile(strSigFilePath &amp; "Oliv.htm")
    strBuffer = objSignatureFile.ReadAll

    SplitAtt = Split(strBuffer, "src=""", , vbTextCompare)
    If UBound(SplitAtt) &gt; 0 Then
        strAtt = Split(SplitAtt(1), """")(0)
    End If
    objSignatureFile.Close

    Set objMsg = Application.CreateItem(olMailItem)
    With objMsg
        .Subject = "Subject goes here"
        .HTMLBody = "&lt;p&gt;Something here.&lt;/p&gt;&lt;p&gt; &lt;/p&gt;" &amp; strBuffer
        
        If strAtt &lt;&gt; "" Then
            Set EmbAtt = .Attachments.Add(strSigFilePath &amp; Replace(strAtt, "/", "\"))
            If InStr(1, objMsg.HTMLBody, strAtt, vbTextCompare) &gt; 0 Then
                objMsg.HTMLBody = Replace(objMsg.HTMLBody, strAtt, "cid:" &amp; EmbAtt.DisplayName)
            End If
        End If

        .Display
    End With

End Sub

0
-1
Reply
blake
June 7, 2017 4:57 pm

I tried running this macro in Outlook 2016 and it will not run "Compile error: User-defined type not defined."

Does this only work for certain Outlook versions? Was hoping to get this to work on 2016

0
0
Reply
Diane Poremsky
Author
Reply to  blake
June 7, 2017 10:09 pm

It works in all the current versions. In the VBEditor's Tools, References, is the Microsoft Word object library checked? (It looks li8ke i forgot to mention that in the instructions.)

0
0
Reply
Diane Poremsky
Author
Reply to  Diane Poremsky
June 7, 2017 10:41 pm

You can edit the code to use late binding (which will avoid the need to set the word object model), but not all word features will be available if you do this - in the macro no this page, specifically the few lines that set a border will error.
To use late binding instead - add these to up at the top with the other dim statements:
Dim Word As Object
Set Word = CreateObject("Word.Application")

then change these two to use object -
Dim olInspector As Outlook.Inspector
Dim olDocument As object 'Word.Document
Dim olSelection As object ' Word.Selection

0
0
Reply

Visit Slipstick Forums.
What's New at Slipstick.com

Latest EMO: Vol. 30 Issue 29

Subscribe to Exchange Messaging Outlook






Support Services

Do you need help setting up Outlook, moving your email to a new computer, migrating or configuring Office 365, or just need some one-on-one assistance?

Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • Week Month All
  • Jetpack plugin with Stats module needs to be enabled.
  • Move Deleted Items to Another Folder Automatically
  • Open Outlook Templates using PowerShell
  • Count and List Folders in Classic Outlook
  • Google Workspace and Outlook with POP Mail
  • Import EML Files into New Outlook
  • Opening PST files in New Outlook
  • New Outlook: Show To, CC, BCC in Replies
  • Insert Word Document into Email using VBA
  • Delete Empty Folders using PowerShell
  • Warn Before Deleting a Contact
Ajax spinner

Recent Bugs List

Microsoft keeps a running list of issues affecting recently released updates at Fixes or workarounds for recent issues in classic Outlook (Windows).

For new Outlook for Windows: Fixes or workarounds for recent issues in new Outlook for Windows .

Outlook for Mac Recent issues: Fixes or workarounds for recent issues in Outlook for Mac

Outlook.com Recent issues: Fixes or workarounds for recent issues on Outlook.com

Office Update History

Update history for supported Office versions is at Update history for Office

Outlook Suggestions and Feedback

Outlook Feedback covers Outlook as an email client, including Outlook Android, iOS, Mac, and Windows clients, as well as the browser extension (PWA) and Outlook on the web.

Outlook (new) Feedback. Use this for feedback and suggestions for Outlook (new).

Use Outlook.com Feedback for suggestions or feedback about Outlook.com accounts.

Other Microsoft 365 applications and services




New Outlook Articles

Move Deleted Items to Another Folder Automatically

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Google Workspace and Outlook with POP Mail

Import EML Files into New Outlook

Opening PST files in New Outlook

New Outlook: Show To, CC, BCC in Replies

Insert Word Document into Email using VBA

Delete Empty Folders using PowerShell

Warn Before Deleting a Contact

Newest Code Samples

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Insert Word Document into Email using VBA

Warn Before Deleting a Contact

Use PowerShell to Delete Attachments

Remove RE:, FWD:, and Other Prefixes from Subject Line

Change the Mailing Address Using PowerShell

Categorize @Mentioned Messages

Send an Email When You Open Outlook

Delete Old Calendar Events using VBA

VBA Basics

How to use the VBA Editor

Work with open item or selected item

Working with All Items in a Folder or Selected Items

VBA and non-default Outlook Folders

Backup and save your Outlook VBA macros

Get text using Left, Right, Mid, Len, InStr

Using Arrays in Outlook macros

Use RegEx to extract message text

Paste clipboard contents

Windows Folder Picker

Custom Forms

Designing Microsoft Outlook Forms

Set a custom form as default

Developer Resources

Developer Resources

Developer Tools

VBOffice.net samples

SlovakTech.com

Outlook MVP David Lee

Repair PST

Convert an OST to PST

Repair damaged PST file

Repair large PST File

Remove password from PST

Merge Two Data Files

Sync & Share Outlook Data

  • Share Calendar & Contacts
  • Synchronize two computers
  • Sync Calendar and Contacts Using Outlook.com
  • Sync Outlook & Android Devices
  • Sync Google Calendar with Outlook
  • Access Folders in Other Users Mailboxes

Diane Poremsky [Outlook MVP]

Make a donation

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

Productivity

Productivity Tools

Automatic Message Processing Tools

Special Function Automatic Processing Tools

Housekeeping and Message Management

Task Tools

Project and Business Management Tools

Choosing the Folder to Save a Sent Message In

Run Rules on messages after reading

Help & Suggestions

Submit Outlook Feature Requests

Slipstick Support Services

Buy Microsoft 365 Office Software and Services

Visit Slipstick Forums.

What's New at Slipstick.com

Home | Outlook User | Exchange Administrator | Office 365 | Outlook.com | Outlook Developer
Outlook for Mac | Common Problems | Utilities & Addins | Tutorials
Outlook & iCloud Issues | Outlook Apps
EMO Archives | About Slipstick | Slipstick Forums
Submit New or Updated Outlook and Exchange Server Utilities

Send comments using our Feedback page
Copyright © 2025 Slipstick Systems. All rights reserved.
Slipstick Systems is not affiliated with Microsoft Corporation.

:wpds_smile::wpds_grin::wpds_wink::wpds_mrgreen::wpds_neutral::wpds_twisted::wpds_arrow::wpds_shock::wpds_unamused::wpds_cool::wpds_evil::wpds_oops::wpds_razz::wpds_roll::wpds_cry::wpds_eek::wpds_lol::wpds_mad::wpds_sad::wpds_exclamation::wpds_question::wpds_idea::wpds_hmm::wpds_beg::wpds_whew::wpds_chuckle::wpds_silly::wpds_envy::wpds_shutmouth:
wpDiscuz

Sign up for Exchange Messaging Outlook

Our weekly Outlook & Exchange newsletter (bi-weekly during the summer)






Please note: If you subscribed to Exchange Messaging Outlook before August 2019, please re-subscribe.

Never see this message again.

You are going to send email to

Move Comment