Results 1 to 4 of 4
  1. #1
    4 Star Lounger
    Join Date
    Aug 2001
    Location
    Anaheim, California, USA
    Posts
    560
    Thanks
    17
    Thanked 2 Times in 2 Posts

    Pasting and Selecting a Picture (2003/SP2)

    I am setting up a template with an AutoNew macro. The user has to copy a picture from another program by using Alt-PrintScrn, then they go to Word and create a New document, based on the template. When they do this, they will create 3 -6 documents at a time, flipping back and forth between the program that they are copying the screen shot from and Word. The reason that we are pasting it into Word is because we need to add verbiage to it, then it will be printed.

    The AutoNew macro should paste the picture in the document and then I need to have the program select the picture so that it can be cropped and resized. The problem that I am running is each time we do this, the name of the picture changes, Picture 2, Picture 3, etc., so the macro can't find the picture everytime. This is what I get in my macro when I create it by using Record New Macro:
    Selection.PasteAndFormat (wdPasteDefault)
    ActiveDocument.Shapes("Picture 2").Select
    What do I need to change "Picture 2" so that it will always select the picture, so that I can then format it? Thanks for any help anyone can provide.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Pasting and Selecting a Picture (2003/SP2)

    Does the new document contain any other shapes? If not, you can use ActiveDocument.Shapes(1).Select

  3. #3
    4 Star Lounger
    Join Date
    Aug 2001
    Location
    Anaheim, California, USA
    Posts
    560
    Thanks
    17
    Thanked 2 Times in 2 Posts

    Re: Pasting and Selecting a Picture (2003/SP2)

    Thanks Hans. This is the only shape on the doucment and that worked for me when I run it on my computer.

    I have the template on the Workgroup Template directory and when I try and run it on other computers, I tried it on 2 others, I get the following Microsoft Visual Basic error message:

    Run-time error '-2147024809(80070057)':
    The index into the specified collection is out of bounds.

    When I click on Debug and it opens the editor, the line "ActiveDocument.Shapes(1).Select" is the one that is highlighted. Any ideas on why it would be doing this? Thanks.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Pasting and Selecting a Picture (2003/SP2)

    It probably means that their version of Word by default inserts picture in line with the text instead of as a floating shape. Try this:

    Selection.Paste
    On Error Resume Next
    ' Try to select floating shape
    ActiveDocument.Shapes(1).Select
    If Err Then
    ' If it failed, try to select inline shape
    ActiveDocument.InlineShapes(1).Select
    End If

Posting Permissions

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