VBA Code to Delete Signature from Outlook Email
When automating email from Outlook, You might want to delete the signature that got added autoamtically. So, that you can add a custom signature using the VBA code itself.
So, here is the code that will remove the signature that got added autoamtically.
Sub Remove_Mail_Signature()
'Define
Dim OutApp As Object
Dim OutMail As Object
Dim objDoc As Object
Dim oBookmark As Object
'Init
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
'This step is required before getting the signature
.Display
'Delete the signature
On Error Resume Next
Set objDoc = .GetInspector.WordEditor
Set oBookmark = objDoc.Bookmarks("_MailAutoSig")
If Not oBookmark Is Nothing Then
oBookmark.Range.Delete
End If
On Error GoTo 0
'Add any content to mail body here
strBody = .HTMLBody
'Now send mail
.To = sToAddress
.CC = sCCAddress
.Subject = sSub
.HTMLBody = strBody
.Send
End With
End Sub
Once the mail is displayed on screen, Outlook automatically adds the signature as per your settings. Then we capture the automatically added signature with the bookmark as mentioned above.
These bookmarks cannot be edited in plain text more. So, we get the object to the actual word editor present within the newly created mail. Then we remove the book mark that correspond to the Autosignature.
Before sending the mai, you can additional content to the mail with the variable strbody. Remember this will not have a signature.
Instead of .Send, you can also use .Display to view the mail again to double confirm that the content is correct.
Also, read a similar topic in this page.