Selecting inline picture from Word VBA

H

hmmm...

Hi,

Enhanced metafile produces a picture that floats. In this post I call a
picture that does not float an "inline" picture.

Is there a way of selecting an inline picture from VBA? The picture
originates from Excel. It is copied/pasted using the following code.

Selection.GoTo what:=wdGoToBookmark, Name:="the_chart_bookmark"
exapp.Worksheets("Sheet1").ChartObjects(1).Chart.CopyPicture xlScreen,
xlPicture
Selection.Paste

I tried recording a macro, but in record mode, I could not select the
picture with the mouse. The only way I could select it in record mode was
to use arrow keys, and do a shift-arrow key back over the picture. However,
that recorded code is:

Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend

I want to directly reference the picture and select it. Similar to the way
it can be done for enhanced metafile.

I do not want to do a PasteSpecial specifying enhanced metafile because the
picture floats over the text (I want an inline picture). However, if I do a
PasteSpecial and specify enhanced metafile, then I can select with the mouse
during record mode, and I get the following code:

ActiveDocument.Shapes("Picture 11").Select

Is there anyway I can reference and select an inline picture in a similar
way?

Thanks.
 
H

Helmut Weber

Hi,
how about that:
with activedocument
For i = 1 To .InlineShapes.Count
.InlineShapes(i).Select
Next
End With
Greetings from Bavaria, Germany
Helmut Weber
 
H

hmmm...

Thanks. However, potentially there could be more than one inline picture in
the document. I want to select a particular one. Is there a way to name
the inline picture when it is pasted, so that it can be directly referenced
at a later time?
 
H

Helmut Weber

Hi You noname,
unfortunately, there seems to be no property "name" for
an inlineshape, whereas shapes may have names. (???)
However, before inserting an inlineshape, you may insert
a bookmark and give it a name, so that your inlineshape
is located immediately right of the bookmark, and can
thereby be referenced by:
ActiveDocument.Bookmarks("Marke7").Select
selection.expand
MsgBox Selection.InlineShapes.Count 'Test
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word 97, NT4.0
 

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