Results 1 to 9 of 9
  1. #1
    2 Star Lounger
    Join Date
    Oct 2007
    Posts
    172
    Thanks
    0
    Thanked 2 Times in 1 Post

    AddPicture and Shapes Collection (Word 2003)

    Hi, i need to create a shape object set it equal to a shape created from an image at a known location (filepath).

    I thought I would just create an empty Shapes collection and use the AddPicture method. This works if I use a shapes collection from a header/footer, but I just want to use a local shapes collection. This doesn't work because I get the "object variable not set" error when I try to use the AddPicture method on my locally declared shapes collection, which I guess is because I don't have an instance of the shapes collection object. Using the "new" keyword with the shapes collection within the declaration doesn't work, so I am a bit stuck.

    It's important that I get this image into a local shape object somehow because the rest of my code needs to be independent of where the image came from in the first place.

    Help?

  2. #2
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: AddPicture and Shapes Collection (Word 2003)

    Is there a reason for not using the collection ActiveDocument.Shapes?

    StuartR

  3. #3
    2 Star Lounger
    Join Date
    Oct 2007
    Posts
    172
    Thanks
    0
    Thanked 2 Times in 1 Post

    Re: AddPicture and Shapes Collection (Word 2003)

    Hmm good question. I guess I can use that - i just don't want the image to appear visibly in the document at any point until I add it to a footer.. which leads me on to my second point. If I have a shape object, how can I add it to the footer.shapes collection? The AddShape seems to create a new shape of a defined type - I simply want to copy the shape from the local shape object.

  4. #4
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: AddPicture and Shapes Collection (Word 2003)

    Adding shapes to headers and footers is a minefield. Have a look at this thread for some idea of the issues you need to think about.

    StuartR

  5. #5
    2 Star Lounger
    Join Date
    Oct 2007
    Posts
    172
    Thanks
    0
    Thanked 2 Times in 1 Post

    Re: AddPicture and Shapes Collection (Word 2003)

    I should add that the only reason I am using a shapes collection is because it has the AddPicture method to add a picture using a filepath. If there is another way of getting a picture file on disk (say, a bmp or gif) into a local shape object and then adding this shape object to a footer's shapes collection, then this would solve my problems! At present I can do neither of those two steps because (1) I can't have a local shapes collection and (2) because I can't get the local shape object into the footer's shapes collection because the AddShape seems to create a shape of a particular defined type "msoAutoShapeType".

  6. #6
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: AddPicture and Shapes Collection (Word 2003)

    Why don't you do the whole thing at once. Use AddPicture with a variable that points to the correct file on disk.

    StuartR

  7. #7
    2 Star Lounger
    Join Date
    Oct 2007
    Posts
    172
    Thanks
    0
    Thanked 2 Times in 1 Post

    Re: AddPicture and Shapes Collection (Word 2003)

    Hi yeah, I have read that thread before and I have found out the hard way that this is a minefield. I had pretty much mastered all the other aspects regarding headers/footer types, sections and the sharing of shapes collections etc.

    Previously I was adding a shape to a footer's shapes collection using the AddPicture function and passing in a user-selected filepath. This worked fine. The difference now which I am having trouble with, is that the shape can now come from either of two sources, rather than just the user selection. I need to modify my code accordingly to take this into account. The other potential image source is within the document itself and I can get this easily into a local shape object.

    My aim within the code is to determine the source of the image (i.e. user selected file path or another image (shape) in the document), get the right image into a local shape object (or some other form that isn't dependent on the image source) and insert this into a footer's shapes collection.

  8. #8
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: AddPicture and Shapes Collection (Word 2003)

    The only way I know to add a picture to the Shapes collection is to use the AddPicture method.
    AddShape only adds AutoShapes, it is not what you need here at all.
    If you want a copy of a Picture that is already elsewhere in the document I guess you could use the Copy and Paste methods.

    I think you may have to use slightly more complex code that accepts either a String (and you can use AddPicture) or an existing Shape (and you can Copy/Paste)

    StuartR

  9. #9
    2 Star Lounger
    Join Date
    Oct 2007
    Posts
    172
    Thanks
    0
    Thanked 2 Times in 1 Post

    Re: AddPicture and Shapes Collection (Word 2003)

    thanks for the suggestions. I have had to get round the problem another clever way, but as usual when working in this area with images and footers and things, I end up with some random behaviour. I am now trying to find out why the code works most of the time, but sometimes not, even if apparently all other things remain the same! Wouldn't be the first time..

Posting Permissions

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