Insert Signature image by selecting from a list using a word macro

Posted on 2011-05-12
Last Modified: 2012-05-11
I have never created a Word Macro before, and have been asked by my boss to create one which will insert a signature into a word document.

The admin staff will be doing this work, and will therefore need to be able to select the particular signature they require (not just their own).

The orignal idea was that there would be a drop down list of names, and the signature linked to that name would be inserted onclick, but I have been working on this to no avail for so long now, that I would be happy just to open an insert dialog box, and have all the.jpg files listed in that box, and let the user select from there.

If you can't help me, a link to somewhere which would be able to would also be appreciated.
Question by:admin_lismore
    LVL 76

    Expert Comment

    It is possible to open the Insert Picture dialogue via VBA, but it doesn't buy you very much.

    Logically it should be possible to select the picture to match the Office user or the log-in name, e.g.

    ActiveDocument.InlineShapes.AddPicture "C:\PictureFolder\" & UserName & ".jpg", False, True, Selection.Range

    Note that it is possible to digitally sign a Word document, with or without a picture.

    To give you an idea of what is involved, here is a function from the Word help file:

    Function AddSignature(ByVal strIssuer As String, _
        strSigner As String) As Boolean
        On Error GoTo Error_Handler
        Dim sig As Signature
        'Display the dialog box that lets the
        'user select a digital signature.
        'If the user selects a signature, then
        'it is added to the Signatures
        'collection. If the user does not, then
        'an error is returned.
        Set sig = ActiveDocument.Signatures.Add
        'Test several properties before commiting the Signature object to disk.
        If sig.Issuer = strIssuer And _
            sig.Signer = strSigner And _
            sig.IsCertificateExpired = False And _
            sig.IsCertificateRevoked = False And _
            sig.IsValid = True Then
            MsgBox "Signed"
            AddSignature = True 
        'Otherwise, remove the Signature object from the SignatureSet collection.
            MsgBox "Not signed"
            AddSignature = False 
        End If
        'Commit all signatures in the SignatureSet collection to the disk.
        Exit Function
        AddSignature = False 
        MsgBox "Action canceled."
    End Function

    Open in new window


    Author Comment

    Sorry I should have given more information.

    We don't need the documents to be security signed, all we want is the pretty picture.  It's to stop people creating documents, printing them out, signing them, and then scanning them back in.  So a file open dialog, which points to the exact location of all the "signature" files would be acceptable.

    I apologise again that I have had no experience at all in writing macros..

    LVL 76

    Accepted Solution

    This macro saves the default location for pictures (probably MyPictures), changes it to the signature folder, opens the InsertPicture dialogue for the user to choose, and then resets the default back to what it was.
    Sub InsertSigPic()
        Dim dlg As Dialog
        Dim strOriginalDefault As String
        Dim strSignatureFolder As String
        strSignatureFolder = "\\OurServer\OurSignatureFolder"
        Set dlg = Dialogs(wdDialogInsertPicture)
        strOriginalDefault = Application.Options.DefaultFilePath(wdPicturesPath)
        Application.Options.DefaultFilePath(wdPicturesPath) = strSignatureFolder
        Application.Options.DefaultFilePath(wdPicturesPath) = strOriginalDefault
    End Sub

    Open in new window


    Author Closing Comment

    My problem was actually slightly different to what I thought it was.  TRIM EDMS is getting in the way of changing the default file path.  Will need to speak to our Records Manager,post another question on this.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    I would like to show you some basics you can do with Mailings in MS Word. It´s quite handy feature you can use for creating envelopes, labels, personalized letters etc. First question could be what is this feature good for? Mailing can really he…
    Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
    This video walks the viewer through the process of creating a watermark for their document, customizing it, and saving it for viewing/printing needs.
    Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now