Iterating through all shapes in a document.

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
Dim vsoShapes As Visio.Shapes
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!
 
E

Edward Colvin

I am reposting this to microsoft.public.visio.developer.vba, as that
seems more appropriate. For some reason, I didn't find that group when
I first searched for Visio groups. Operator error, I'm sure. However,
if anyone has any suggestions, your help is appreciated!
 
N

Nikolay Belyh

I am reposting this to microsoft.public.visio.developer.vba, as that
seems more appropriate. For some reason, I didn't find that group when
I first searched for Visio groups. Operator error, I'm sure. However,
if anyone has any suggestions, your help is appreciated!

Dear Edward,
I wanted to inform you that all NNTP-newsgroups
(microsoft.public.***....whatever) were actually cancelled by
Microsoft a few years ago, and are not maintained anymore.

Try posting your question to:
http://social.msdn.microsoft.com/Forums/en/visiogeneral/
or to:
www.visguy.com/vgforum/

As far as I know, at the present time these two are the most "crowded"
Visio developer forums.
I would recommend you to post to one of these forums and additionally
attach a sample drawing to illustrate what you mean.

Kind regards, Nick
 

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