Bringing all shapes with text to the front.

E

Edward Colvin

I am importing multiple SVG files that have to be manually cleaned
up.
One of the problems I encountered is all the text boxes are behind
everything else. I thought I might dust off the VBA skills (which I
have none - I'm a python guy) and make my life a little easier. So I
grabbed some code off the web and tried modifying it to suite my
need:

Sub bring_text_shapes_to_fg()
Dim vsoShape As Visio.Shape
For Each vsoShape In ActivePage.Shapes
If Len(vsoShape.Text) > 0 Then
Debug.Print vsoShape.Text
vsoShape.BringToFront
End If
Next
End Sub

However, it does not work reliably. Sometimes, it misses shapes, and
the text box stays behind the surrounding shapes. Subsequent calls to
same routine will usually find the text boxes it missed the first
time
around. So if I run the sub twice, it will usually get all the text
box shapes. While this is still better than doing it manually, it
offends my sensibilities. It should do the same thing every time!

I included the debug.print statement to see if the BringToFront call
is failing, or if the text boxes that are missed are not found. It
appears to be the latter: when I do search of the output for the text
that remains behind the other shapes, it is not in there. So for some
reason, either "for each" is not actually iterating through all the
shapes, or len(vsoShape.Text) is misfiring.

Is there a better approach here? Or any other suggestions? If there
is
an easy to do this through the GUI, that would be fine, although I
would like to know why it is failing. I am sure this is a code
pattern
I will be using again, if I can get it to work. Any help is
appreciated!
 

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