none
Inserting a signature into office 2010 RRS feed

  • Question

  • Here's the story.  My users want to be able to insert a non-copyable signature into a document using a MS Word macro.  The only other requirement is that they must be able to do this with one click.  Previously they used a macro that did this but didn't really protect the signature...

    Sub insertSig()
    Selection.InlineShapes.AddPicture FileName:="C:\mysig.gif", LinkToFile:=False, _
    SaveWithDocument:= True
    End Sub

    I'm trying to rewrite the code so that it uses the signature lines in Word 2010.  I've gotten this far... kinda :|

    Sub insertSig()
    ActiveDocument.Signatures.AddSignatureLine.Sign("C:\mysig.gif")
    End Sub

    This opens the signatureline dialog box, then opens the signature setup box (where you enter name, e-mail, etc), and pressing OK without changing anything on either eventually gets your signature in and the document locked.

    The other option that would be nice is to have the user select an already created signature line and run the macro which adds the image and locks the file.  This I havn't figured out at all.  My VB is relatively limited, but it appears that's what I have to use for this project.

    Help please?


    • Edited by BWadeDev Wednesday, August 22, 2012 11:52 AM
    Tuesday, August 21, 2012 7:34 PM

Answers

  • Thanks for all your help Cindy.  I looked into SendKeys and that seemed to be the last piece I needed.  I ended up with this code, and it solves my issue pretty well!

    Sub MySigSecure()
    SendKeys "~()~()~", False
    ActiveDocument.Signatures.AddSignatureLine("{00000000-0000-0000-0000-000000000000}").Sign ("C:\mysig.gif")
            
    End Sub

    The issue with SendKeys is that it is sometimes unreliable, but I think for the time being this is the best I can do.  Thanks for all the help!
    • Marked as answer by BWadeDev Monday, August 27, 2012 11:35 AM
    Monday, August 27, 2012 11:35 AM

All replies

  • Hi BwadeDev,

    Thanks for posting in the MSDN Forum.

    Based on your issue, I would recommand the following macro to you for inserting a signature into a word document.

    Sub InsertSig()
     Dim sig As Shape
     Set sig = ActiveDocument.Shapes.AddPicture (Anchor:=Selection.Range, FileName:= "C:\mysig.gif",_
    LinkToFile:=False,SaveWithDocument:=True)
     With sig
        .Name = "mysig"
        .Select
     End With
    ' show the width of the shape
     MsgBox ActiveDocument.Shapes("mysig").Width
    End Sub
    

    Hope this can help you.

    Have a good day.


    Leo_Gao [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, August 22, 2012 7:44 AM
    Moderator
  • Thanks for the help Leo_Gao, but that macro does the same thing the first one I mentioned does.  The other issue with both of them is that after a simple copy/paste your signature is now available for the other person to stick on whatever they want.  The SignatureLine option is preventing copy/paste (you instead just get a copy of a blank signature line) but I can't seem to format it properly for one-click implementation.
    Wednesday, August 22, 2012 11:51 AM
  • Hi,

    It's based on my experience that you can try to use the Word Bookmark as a place holder to hold the signature image. Please refer to

    Application.Selection.GoTo wdGoToBookmark,Name:="Signature"

    Maybe this can be helpful for the issue.

    Best Regards,


    Leo_Gao [MSFT]
    MSDN Community Support | Feedback to us

    Friday, August 24, 2012 3:01 AM
    Moderator
  • Hi BWade (and Leo)

    I'm not really fully familiar with this feature in Word, but I found this page informative:

    http://office.microsoft.com/en-us/excel-help/add-or-remove-a-digital-signature-in-office-files-HA010354308.aspx

    As far as the object model goes, working with Signatures is covered mostly in the Office APIs, not Word, as it's a shared technology.

    There are two aspects to "signing" the document. One is just putting a signature on it, which is what Leo is suggesting. The other is protecting that signature, which he is not addressing.

    When I experiment with the functionality in the UI it requires a digital signature in order to actually sign the document. When that is done, the document becomes "read-only" and the user needs to specifically say he wants to edit the document. When this happens, Word removes the signature (both what's gone on the Signature Line as well as the digital signing).

    Now, when I test copying a signature line that has been properly signed  using the digital signature feature, when I paste the line is there, but the actual signature is gone.

    Adding the signature line into the document is apparently accomplished using ActiveDocument.Signatures.AddSignatureLine("{00000000-0000-0000-0000-000000000000}")

    where the GUID is the ID of the Signature Provider.

    So far, I've not been able to figure the exact code for doing the signing, but apparently the Sign method requires the image to be an IPictureDisp object, not a string value?

    Looking at the Help for the Signature object, it appears you must first add a SignatureSet to the document. Once you've done that, you can access individual Signature objects and the Sign method will apparently work only on these. Apparently, this is done over the Document.Signatures.Add method, although I'm not seeing this via the VBA object model.

    The only way I can see in VBA is to use AddSignatureLine which displays the dialog box. Using SendKeys, I can make it work without bothering the user with the dialog box:

    SendKeys "Cindy Meister{tab}{tab}cindymeister@email{Enter}"
        ActiveDocument.Signatures.AddSignatureLine _
            "{00000000-0000-0000-0000-000000000000}"
    From a remark in one of the Help items, it's possible that the full Signature object model is only available to a COM Add-in (such as you can create using VSTO). There are other object methods where this is true that also involve "trust validation", so you may need to go that route if you also want to sign the document for the author.


    Cindy Meister, VSTO/Word MVP

    Friday, August 24, 2012 4:13 PM
    Moderator
  • Thanks for all your help Cindy.  I looked into SendKeys and that seemed to be the last piece I needed.  I ended up with this code, and it solves my issue pretty well!

    Sub MySigSecure()
    SendKeys "~()~()~", False
    ActiveDocument.Signatures.AddSignatureLine("{00000000-0000-0000-0000-000000000000}").Sign ("C:\mysig.gif")
            
    End Sub

    The issue with SendKeys is that it is sometimes unreliable, but I think for the time being this is the best I can do.  Thanks for all the help!
    • Marked as answer by BWadeDev Monday, August 27, 2012 11:35 AM
    Monday, August 27, 2012 11:35 AM
  • I have been looking for a line of code like this for the past week!

    Thank you so much

    Thursday, August 4, 2016 1:44 PM