How do I get the total number of graphics/pictures in a word doc?

R

Ryan Dunn

I'm writing a macro that iterates through a word document and operates on
each picture it finds. I need to be able to find the total number of
pictures in the file to control the for loop. I have successfully done this
with tables using ActiveDocument.Tables.Count, but there seems to be no such
variable for graphics. Using Selection.GoTo one can jump to the next
graphic, so I know that word has graphics flagged, but I need to know how
many so I know when to stop. Any ideas?

Thanks,
Ryan
 
G

Greg Maxey

Ryan,

Are you working with shapes in the shaperange or inline shapes (in line with
text)?

Sub Test()
MsgBox ActiveDocument.InlineShapes.Count
MsgBox ActiveDocument.Range.ShapeRange.Count
Dim oShape As Shape
For Each oShape In ActiveDocument.Range.ShapeRange
MsgBox oShape.Type
Next
For Each oILS In ActiveDocument.Range.InlineShapes
MsgBox oILS.Type
Next oILS
End Sub
 
R

Ryan Dunn

I'm not sure, but I think that the pictures are inline with the text. If the
cursor is to the left of the picture, when I press right, it selects the
picture, and another right button press moves the cursor to the right of the
picture. The cursor is along the lower edge of the picture. I appologize
for my ignorance on this issue, I'm just starting out with Word macros. Are
those the only two types of graphics within a Word document? The "or" in
your question implies only two options, but I want to be sure.

Thanks,
Ryan
 
R

Ryan Dunn

I mis-spoke, when moving the cursor, the picture is not selected, but if I
hold down the shift key it is. I'll try your suggestions to see what works.

Thanks again,
Ryan
 

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