PDA

View Full Version : [SOLVED:] How to cycle through all inline images in a document but skip those in Sections 1 & 2



dbowlds
03-27-2018, 05:55 AM
Hello, can anyone please tell me how I can cycle through all inline images in a document, skipping any found in sections 1 and 2, and skipping any that are inline text boxes, and loading those images remaining into an array?

I know this request is similar to a number of other posts (some very old) in this forum, and I have experimented with the code in those posts, but cannot for the life of me figure out how to skip the images in the first two document sections and skip those items that are actually inline text boxes.

If anyone can point me in the right direction, I would be very appreciative.

Doug

macropod
03-27-2018, 06:05 PM
So what do you want to skip - textboxes anywhere, or textboxes and other inlineshapes in Sections 1 & 2?

dbowlds
03-28-2018, 02:23 AM
Paul, I would want to skip all textboxes anywhere in the document plus the entire document sections 1 and 2.
Doug

macropod
03-28-2018, 02:57 PM
Even if you format a textbox as inline, Word doesn't count it as an inlineshape object. Accordingly, the following should work:

Sub GetInlinePics()
Dim i As Long, j As Long
With ActiveDocument
For i = 3 To .Sections.Count
With .Sections(i).Range
For j = 1 To .InlineShapes.Count
With .InlineShapes(j)
'process the InlineShape here
End With
Next
End With
Next
End With
End Sub
It's not clear to me what you mean about "loading those images remaining into an array".

dbowlds
03-29-2018, 05:15 AM
Hi Paul, thank you for responding. Your code was what I needed. Thank you.

My comment re: shapes into an array was a misguided path I was headed down. Instead, I found a wonderful piece of code on this forum (I think perhaps written by you) that used an array to capture the image caption and then saved the images to a folder (by saving the document as an HTML document and then stripping out the extraneous files) and then renaming the resultant image file names to match the captions saved in the array. The issue I was running into is that when you save a Word document as an HTML document and then look at the images, for some reason text boxes are considered to be images and, since in my document they do not have captions, it seemed to be throwing off the renaming action. Regardless, after further consideration, I realized I also wanted to capture the text boxes from the document and the fact that they were captured and saved along with the rest of the actual images, was golden!
Net results: I'm good and very much appreciate your help.
I will flag this as solved.
Doug
Hopefully this makes sense.