Replace Shape picture

J

Jim

I need to insert a picture (a metafile) into a template Word document, using
a Shape so it can be explicitly positioned on the page. I know I can delete
the existing Shape and recreate/position a new Shape. I was curious if you
can simply replace the picture in an existing placeholder Shape? This can
be done with an InlineShape by selecting it and Selection.PasteSpecial. But
the same technique with a Shape seems to always add a new Shape (whether I
use AShape.Select True or False).

TIA,
Jim
 
A

alborg

Hi Jim:

There is a code that might be of interest to you that uses a bookmark to
establish the positioin of the shape, then replaces it with another shape.
The URL is:

http://www.wiredbox.net/Forum/Thread330710_Replace_exisiting_image_programatically.aspx

If you wish to retain the capability of reinserting the original shape, you
can simply use an array to check to see if the shape is "shape1" and if not,
to put it back in.

Unlike in UserForms or in MS Access Forms, I don't think that you can really
hide the shape on a document, which is what you seemingly wish to do.

Cheers,
Al
 
J

Jim

That example deletes the existing shape and re-Adds, and also uses
InlineShapes. I'm thinking that a Shape is a container for a picture, so
why not just stuff a new picture into the existing container? May not be
possible. But thanks anyway.
 
J

Jean-Guy Marcil

Jim was telling us:
Jim nous racontait que :
That example deletes the existing shape and re-Adds, and also uses
InlineShapes. I'm thinking that a Shape is a container for a
picture, so why not just stuff a new picture into the existing
container? May not be possible. But thanks anyway.

A shape is not a container for a picture, it is an object just like a
picture is.

You could insert a picture inside a textbox, but it would have to be inline.

Or else, look up the Canvas object in the VBA help and see Tools >
Options... > General tab > Automatically create drawing canvas when
inserting autoshapes.
The drawing canvas can act as a container fro a floating picture.

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Jim

It's a "container" in the sense that the object contains image data, as well
as other properties like position and name. My question was can I just
replace the image data w/o deleting and re-creating the object (which sounds
like more work, hence slower). Apparently the answer in no. You can
replace the image with an InlineShape but I need a Shape for the page
positioning.

Thanks,
Jim
 
J

Jean-Guy Marcil

Jim was telling us:
Jim nous racontait que :
It's a "container" in the sense that the object contains image data,
as well as other properties like position and name. My question was

Well, expressed this way, any object is a container... All objects have a
position, a name, some content.. etc. ;-)
can I just replace the image data w/o deleting and re-creating the
object (which sounds like more work, hence slower). Apparently the

If the image is floating, and you want to replace it by another, just record
its position and size, delete it, insert the new one and applied the
previously saved parameters to the new image.

Yes. it is more work, but it will be fast (Fast in execution, maybe slow in
writing the code...)
answer in no. You can replace the image with an InlineShape but I
need a Shape for the page positioning.

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Jim

Well, expressed this way, any object is a container... All objects have a
position, a name, some content.. etc. ;-)

It's not quite that silly. If you would like another example of the
"container" idea, consider an Image control on a Form. You can change
Image.Picture without replacing the Image control itself. That's what I was
looking for with a Shape (Shape.Picture = ...).

Anyway, got my answer and guess I shouldn't worry about speed.

Jim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top