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

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.
Who is Participating?
GrahamSkanConnect With a Mentor RetiredCommented:
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

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

admin_lismoreAuthor Commented:
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..

admin_lismoreAuthor Commented:
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.