This macro shows how to remove a signature from a message using VBA when you are composing a message. While this macro won't save a lot of time as it's almost as easy just to select and delete it, you can add it to macros that do other things. Because it uses the ActiveInspector, it will work best with macros that automate replying, such as "VBA Sample: Do Something When Reply is Clicked".
Sub RemoveSignature() Dim Item As Outlook.MailItem Set Item = Application.ActiveInspector.CurrentItem Dim objDoc As Word.Document Dim oBookmark As Word.Bookmark On Error Resume Next Set objDoc = Item.GetInspector.WordEditor Set oBookmark = objDoc.Bookmarks("_MailAutoSig") If Not oBookmark Is Nothing Then oBookmark.Select objDoc.Windows(1).Selection.Delete End If Set Item = Nothing End Sub
If you use this macro in a run a script rule, you'll need to use .Display to show the inspector and will see a flash on the screen as the message is opened, the signature removed, and then sent.
Tip: if you don't want to use a signature when a macro creates a new message, you can use item.body = "" or copy the body from a message to send without a signature.
For example, you can combine the macro with one that adds a note to the body and removes the signature:
Sub ReplywithNote() Dim Item As Outlook.MailItem 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 olSelection.InsertBefore "This is my note" Set oBookmark = olDocument.Bookmarks("_MailAutoSig") If Not oBookmark Is Nothing Then oBookmark.Select olDocument.Windows(1).Selection.Delete End If ' uncomment to send 'myReply.Send End Sub
Macro samples to insert signatures are available at
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:
- Right click on Project1 and choose Insert > Module
- Copy and paste the macro into the new module.
More information as well as screenshots are at How to use the VBA Editor.
Hello, running into issues with the Dim assignments. Get error not defines for this step "Dim olDocument As Word.Document" Its for the remove sig and add not sections of the macro
You may need to set a reference to the word object model. In the VB editor: Tools > references.
First off, you are awesome! It was a prayer responding to this thread given the time of the last post. So glad you are still monitoring this :). So I tried that but the option is grayed out. Just a little background, as I know the OP was very generic. So at work we get hit a lot with spam email. A co-worker created a quick step to reply to the email with the generic labels to opt out, but the email contains his signature info. We can not change our sigs, its an AD restriction. SO I was looking to see if either the quick step could do this step of removing the sig, which I do not believe is able. Or create a macro to reply to the email and remove the sig. I am no programmer, but out of the group of 3, I'm the best bet. TY for your time and advice.
>> So I tried that but the option is grayed out.
is the macro is in debug state? The macro can't be running when you go to enable it.
Almost got this to be exactly what I am looking for. I modified the code just a bit to line up with my objective. I just have another question regarding the subject. So when I respond to a piece of spam mail, I want to be able to change the subject line with "Unsubscribe". I added an If / Then thinking it would handle the requirement, which it does...sort of. In the initial reply, the subject stays the same as the original. But if I close the message and run the macro again, it will then replace the original subject, with the "Unsubscribe" verbiage. I have included what I did so far. Any idea what I might be doing wrong? Sub ReplytoSpam() Dim Item As Outlook.MailItem Set Item = Application.ActiveExplorer.Selection.Item(1) Dim olInspector As Outlook.Inspector Dim olDocument As Word.Document Dim olSelection As Word.Selection 'Begin reply to active email routein Set myReply = Item.Reply myReply.Display If Item.Subject <> "Unsubscribe" Then Item.Subject = "Unsubscribe" End If Set olInspector = myReply.GetInspector Set olDocument = olInspector.WordEditor Set olSelection = olDocument.Application.Selection olSelection.InsertBefore "Unsubscribe, Opt-Out, Leave Out, Stop, Can Spam" ' Begin signature removal routein Set oBookmark = olDocument.Bookmarks("_MailAutoSig") If Not oBookmark Is Nothing Then oBookmark.Select… Read more »
does it work better to move the display line below the new subject line.
Set myReply = Item.Reply
If Item.Subject <> "Unsubscribe" Then
Item.Subject = "Unsubscribe"
myReply.Display
End if
no, it actually changes the original subject of the email, rather then to the reply of the email.
Did a little more digging, and looks like when I ran my code, the editor was still "engaged" after clicking ok to the error message. Clicked the stop button, saved the code and going back into the editor the reference section was now available. I assumed the MS Office selection was all that was needed to make the reference, but doing a little more research, I found out I needed the MS Word reference selected as well. Got that, and bam, script ran and outputted what I was expecting. Thank you so much for your time. Going to keep this site book marked. Something tells me I'm going to be expected to learn to code.
Thanks for this code. Was wondering how you would go about deleting an image that is in the signature. The code above works to delete the signature but it leaves the image that is in the signature.
You need to remove the attachment
If there are other attachments, you need to check the file size or file type too.
if oAttachments(1).size < 5012 then or if right( oAttachments(1).name, 3) = "png") then
Thanks for the quick reply.
The doesn't really delete the image in the signature. It removes the attached image so now in the email body the image is still there but instead of the actual image that was in my signature it is now the red x box saying the picture can't be displayed.
So the signature code is not being removed. Is this a signature in quoted parts of the message or the signature add to the new message?
When I run the code, it removes the text portion of the signature, and the image, but into the image tag. See the attached screen shot.
i will need to test the macro and see why its failing. It should remove everything in the auto sig style, including the image.
Hi, I am trying to run the code in Excel, however, I would get the error message "Object doesn't support this property"?
is there any reference or library I should add to make this work?
you need to reference the word object model.
Hi Daine
Please help me to get signature through VBA code as i m using default signature in mail.
Please provide that code line
Do you need to add a signature or remove it? The code on this page will remove your signature. The macros at https://www.slipstick.com/outlook/email/create-new-message-using-html-file-stationery/ can also be used to insert a signature in a new message.