none
Removing signature from CreateItemFromTemplate RRS feed

  • Question

  • Hello,

    I have a problem. When I try to save a .msg file with CreateItemFromTemplate there is included my signature inside and I don't want it there. Is there any way to remove it (I need to make this macro universal, so not only change it in templates at my computer, but remove it whenever has this signature) ?  Maybe there is a way to save email in another way (I need to later open it with MS Word)?

    This is very short part of my macro with it (maybe it can make my question easier): 

    Set openMsg = Application.CreateItemFromTemplate(path1& scmsg)

    openMsg.SaveAs path1 & nrm & ".htm", olHTML

    Thank you for your help.

    Best regards,
    Robert

    Wednesday, April 8, 2015 1:37 PM

Answers

  • Rob,

    The signature files (txt, rtf, html) are stored in the [Roaming AppData]\Microsoft\Signatures folder for the current user. You can read the file content in the appropriate format and try to find the same content on the message body.

    You can use the Word object without saving the mail item and then re-opening it in Word anew. The WordEditor property of the Inspector class returns an instance of the Document class which represents the message body. See Chapter 17: Working with Item Bodies for more information.

    The Word object model provides the ExportAsFixedFormat method for the Document, Range and Selection classes. You can use it to save the message using the .pdf file format.

    • Marked as answer by RobRaj Thursday, April 9, 2015 1:22 PM
    Thursday, April 9, 2015 11:58 AM

All replies

  • Hello Robert,

    The Outlook object model doesn't provide any special methods for working with signatures. You need to edit the message body to remove the signature. The following properties can be used to get the job done:

    1. Body - a raw text.

    2. HTMLBody - a html markup which represents the message body.

    3. The Word editor. The WordEditor property of the Inspector class returns an instance of the Document class which represents the message body. You can use the Word object model to make any modifications. Moreover, you can save the body as a Word document if you need to open it later in Word.

    Wednesday, April 8, 2015 1:52 PM
  • Hello, 

    Thank you for your answer. Anyway I still don't have any idea how to do it. Like I said I want to make this macro universal, so even if I set it to remove this underpart of massage manually or even find the break which precede it it still can don't work properly because someone signature can look different. 

    Do you know if there is any other option to download .msg file and covert it later to pdf? For now I was doing it with this CreateItemFromTemplate and opening later with Word (which makes this problem with signature), but maybe there is other way to do it?

    Best regards,
    Robert

    Thursday, April 9, 2015 11:41 AM
  • Rob,

    The signature files (txt, rtf, html) are stored in the [Roaming AppData]\Microsoft\Signatures folder for the current user. You can read the file content in the appropriate format and try to find the same content on the message body.

    You can use the Word object without saving the mail item and then re-opening it in Word anew. The WordEditor property of the Inspector class returns an instance of the Document class which represents the message body. See Chapter 17: Working with Item Bodies for more information.

    The Word object model provides the ExportAsFixedFormat method for the Document, Range and Selection classes. You can use it to save the message using the .pdf file format.

    • Marked as answer by RobRaj Thursday, April 9, 2015 1:22 PM
    Thursday, April 9, 2015 11:58 AM
  • Thank you! 

    At this chapter I fount what I looked from beginning. Now everything works properly. I paste parte with removing signature here, maybe it will be useful for someone. 

    Sub DeleteSig(msg As Outlook.MailItem)
        Dim objDoc As Word.document
        Dim objBkm As Word.Bookmark
        On Error Resume Next
        Set objDoc = msg.GetInspector.WordEditor
        Set objBkm = objDoc.Bookmarks("_MailAutoSig")
        If Not objBkm Is Nothing Then
            objBkm.Select
            objDoc.Windows(1).Selection.Delete
        End If
        Set objDoc = Nothing
        Set objBkm = Nothing
    End Sub
    
    

    Thursday, April 9, 2015 1:22 PM