• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 456
  • Last Modified:

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.
0
admin_lismore
Asked:
admin_lismore
  • 2
  • 2
1 Solution
 
GrahamSkanCommented:
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.
    Else
        sig.Delete
        MsgBox "Not signed"
        AddSignature = False 
    End If

    'Commit all signatures in the SignatureSet collection to the disk.
    ActiveDocument.Signatures.Commit

    Exit Function
Error_Handler:
    AddSignature = False 
    MsgBox "Action canceled."
End Function

Open in new window

0
 
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..

Thanks
0
 
GrahamSkanCommented:
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
    dlg.Show
    Application.Options.DefaultFilePath(wdPicturesPath) = strOriginalDefault
End Sub

Open in new window

0
 
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.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now