Tuesday, 13 August 2013

Visio VBA: Invalid Parameter in Nested Loop

Visio VBA: Invalid Parameter in Nested Loop

In Microsoft Visio Professional 2010 I've isolated the error I've been
getting to this little code snippet. On the page is a container holding 2
shapes and I want to iterate through those shapes within another loop. But
I keep getting an invalid parameter error.
My attempt at a solution is the top block, but it only works with the same
definition for the inner loop. It seems like something is changing during
the 2nd iteration of the outer loop, but I'm not sure. I feel it has to do
with the way a For Each loop is defined.
Sub Nested_Loop_Error()
Dim a As Variant
Dim b As Variant
Dim lngs() As Long
'This Works
lngs =
ActiveDocument.Pages(1).Shapes.ItemFromID(1).ContainerProperties.GetMemberShapes(visContainerFlagsDefault)
For a = 0 To 1
For Each b In lngs
'Do nothing
Next b
Next a
'This does not work
For a = 0 To 1
For Each b In
ActiveDocument.Pages(1).Shapes.ItemFromID(1).ContainerProperties.GetMemberShapes(visContainerFlagsDefault)
MsgBox "In Loop for a=" & a
Next b
Next a
End Sub

No comments:

Post a Comment