Results 1 to 3 of 3
  1. #1
    Star Lounger
    Join Date
    May 2009
    Posts
    84
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Word 2002 - Name & select a picture after adding to document (VBA included)

    Word 2002

    This code inserts a signature.png from an H drive into Word. When I record a keystroke macro to select the inserted picture, it gives it a name such as "picture 17" which only applies to that document. Next time macro is recorded it might be "picture 4". What code is needed to name the picture so it is selected (and remains selected) after the macro has ended. The selected state allows user to easily move and resize the signature without accessing the Select Objects button in the drawing tool bar. Or, if it's not necessary to name the picture, what code is needed to select it?

    Thanks,
    Charlie
    charlie6067


    With ActiveDocument.Shapes.AddPicture(Anchor:=Selection .Range, FileName:= _
    "H:\E-Signature-DO NOT DELETE\Signature.png", LinkToFile:=False, _
    SaveWithDocument:=True)
    .WrapFormat.Type = 3
    .ZOrder 5
    End With

  2. #2
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    Willow Grove, Pennsylvania, USA
    Posts
    205
    Thanks
    4
    Thanked 49 Times in 40 Posts
    You don't need to name it, all you need is to add the line

    .Select

    after the .ZOrder line.

    If you do want to name it so that you could do more stuff with it later in the macro, then you could modify it this way:
    Code:
    Dim sig As Shape
    Set sig = ActiveDocument.Shapes.AddPicture(Anchor:=Selection.Range, FileName:= _
        "H:\E-Signature-DO NOT DELETE\Signature.png", LinkToFile:=False, _
        SaveWithDocument:=True)
    With sig
        .Name = "e-signature"
        .WrapFormat.Type = 3
        .ZOrder 5
        .Select
    End With
    
    ' ... later...
    
    ' use the name as an index into the Shapes collection
    MsgBox ActiveDocument.Shapes("e-signature").Width

  3. #3
    Star Lounger
    Join Date
    May 2009
    Posts
    84
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you JJ for the quick reply. I will try the code.
    Charlie
    charlie6067

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •