Consulting

Results 1 to 5 of 5

Thread: How to cycle through all inline images in a document but skip those in Sections 1 & 2

  1. #1
    VBAX Regular
    Joined
    Mar 2018
    Location
    Leesburg
    Posts
    68
    Location

    How to cycle through all inline images in a document but skip those in Sections 1 & 2

    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

  2. #2
    VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    So what do you want to skip - textboxes anywhere, or textboxes and other inlineshapes in Sections 1 & 2?
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    VBAX Regular
    Joined
    Mar 2018
    Location
    Leesburg
    Posts
    68
    Location
    Paul, I would want to skip all textboxes anywhere in the document plus the entire document sections 1 and 2.
    Doug

  4. #4
    VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    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".
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  5. #5
    VBAX Regular
    Joined
    Mar 2018
    Location
    Leesburg
    Posts
    68
    Location
    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •