WORD VBA - Looping through ActiveDocument.InlineShapes and the loop maxes out at 100

598 Views Asked by At

Application = MS WORD

Script = VBA

I am trying to loop through each "ActiveDocument.InlineShapes" in a word document. This document contains approximately 300 InlineShapes and I want to traverse through it until I find the one I need

In my case when looping through objects, the loop ends/maxes out at object count of 100.

For x = 1 To ActiveDocument.InlineShapes.Count
    If ActiveDocument.InlineShapes(x).OLEFormat.Object.Name = "chkbx_fc17") Then
            Set var_checkbox_obj = ActiveDocument.InlineShapes(x).OLEFormat.Object
            Exit For
    End If
Next x

I captured the variable values using watch and I see "x" = 101 and object variables show error

Watch window

Is there a different way where the object can be traversed through without a limit of 100?

Used the following references but no go

Can you use the name of a Check-box to access its value?

1

There are 1 best solutions below

0
macropod On BEST ANSWER

There is no upper limit on how many inlineshapes such a loop can process. A slightly different approach:

Dim iShp As InlineShape
For Each iShp In ActiveDocument.InlineShapes
  With iShp
    If .Type = wdInlineShapeOLEControlObject Then
      If .OLEFormat.Object.Name = "chkbx_fc17" Then
        Set var_checkbox_obj = .OLEFormat.Object: Exit For
      End If
    End If
  End With
Next