Can images be named and then searched for?

K

kiln

Is there any mechanism for naming images (shapes, inline shapes,
whatever, I'm not actually clear on the difference between them). I'd
like to be able to loop through the images in a doc and see if a certain
one has been inserted. The image that I'd be looking for would have been
added via code, so I have the oppty to enforce the name of the object,
if that's possible.

Thanks
 
J

Jezebel

Shapes yes, InlineShapes no. However inline shapes can be bookmarked, so you
could name them that way. The difference between Shapes and InlineShapes: in
the document it refers to the Wrapping style (on the Format > Object >
Layout style tab). 'Inline with text' vs all the others. Inline shapes are
handled as part of the paragraph to which they are anchored; non-inline
shapes are floating. In VBA, the difference is that they are in different
collections (ActiveDocument.Shapes, ActiveDocument.InlineShapes).

Objects in the Shapes collection have names, which you can change --

Dim pShape as Shape
Set pShape = ActiveDocument.Shapes.AddPicture(FileName:=...)
pShape.Name = "La Joconde"
 
K

kiln

OK, thanks, that clarifies a couple of items for me, I'll see what I can
make of them.

One question, could you give me a one or two liner, sample code, how an
inline shape can be bookmarked?
 
J

Jezebel

Dim pInlineShape As InlineShape

Set pInlineShape =
ActiveDocument.InlineShapes.AddPicture(FileName:="...\guernica.jpg")
ActiveDocument.Bookmarks.Add Name:="Guernica", Range:=pInlineShape.Range
 
K

kiln

Thank you..to complete my education...is there any way to tell by
looking at a doc or the images properties if a visible image is a shape,
or an inline shape? And can an inline shape be "named" manually?

Thanks
 
K

kiln

OK, on rereading you've already told me that it's the layout wrapping
style that determines if it's an inline shape or just a shape. I see
that I can switch from one type to another. This is really helpful. Next
I'll see if I can rename a shape in vba. Thanks!
 
J

Jay Freedman

If you select a picture in the document, it's an inline shape if:

- its sizing handles are black squares
- when you drop down the Wrapping menu on the Picture toolbar, or go
to the Format Picture dialog and click the Layout tab, the
"In Line With Text" item is selected
- when you drag it, you get the same kind of mouse pointer as when you
drag text, and no dashed outline

It's a shape if:

- its sizing handles are black circles with white centers, and there
is a green rotation handle attached to the top edge
- when you drop down the Wrapping menu on the Picture toolbar, or go
to the Format Picture dialog and click the Layout tab, any item
*except* "In Line With Text" item is selected
- when you drag it, you get a four-headed arrow mouse pointer and a
dashed outline

The method for manually naming an inline shape is the analogue of the
VBA method Jezebel described: select the shape, go to Insert >
Bookmark, and enter the name. The name actually belongs to the
bookmark, not to the picture itself, but the distinction isn't
important if all you use it for is to go to it.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
J

Jezebel

Also note that there's a mistake in the documentation: it says that the add
methods of the InlineShapes collection (like AddPicture) return a Shape
object. This is incorrect. They return an InlineShape object.
 

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