VBA : how to ungroup all shapes ?

M

Moumoute83

I'm asking if it's possible to ungroup all shapes of my ActiveWindow at one
time (that can contain others grouped shapes within) ? Is there a function
better than "Application.ActiveWindow.Selection.Ungroup" ? (< here it
ungroups all shapes but just on one level of grouped shapes).
Am I obliged to create a loop that ungroup level by ungroup "sub-level" ?

I'm not sure if I'm clear.
Thanks for your help.
 
C

Chris Roth [Visio MVP]

Hi Moumoute,

There's no "Ungroup everything completely" method.

You could do a SelectAll in the ActiveWindow several times and ungroup
that, but there would still not be a proper analysis to determine if any
groups are left on the page. If you know the level of grouping likely to
exist, this might work for you. But this is pretty un-disciplined.

A better way might be to get a selection of all Groups on a page. See
"Page.CreateSelection" in the Developer Reference Help. This will return
a Visio Selection object, which is essentially a collection of Visio
shapes. Nothing will be selected in the ActiveWindow. This is a
different notion of "Selection" :)

Once you have the groups, the Shape object also supports the Ungroup
method. This is probably better than working on the ActiveWindow's
selection.

Plus, with a Shape object, you can check to see if the shape is an
instance of a master, which you might NOT want to ungroup. Something
like this:

If Shape.Master Is Nothing Then
' Ungroup
Else
' Don't ungroup master-instances
End If



--
Hope this helps,

Chris Roth
Visio MVP


Visio Guy: Smart Graphics for Visual People
http://www.visguy.com
 
J

John Marshall, MVP

I would be careful of doing a global ungroup because Ungroup is a
distructive command. When shapes are grouped, a new top level shape is
created that may contain extra information added by the developer.
Ungrouping will destroy this shape and the extra information is lost. So for
most cases, Ungroup is not reversible.

John... Visio MVP

Need stencils or ideas? http://visio.mvps.org/3rdparty.htm
Need VBA examples? http://visio.mvps.org/VBA.htm
Visio Wishlist http://visio.mvps.org/wish_list.htm
 

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