How to Group 2 shapes by name with VBA Code?

G

Gary

I have two shapes that I need grouped. I used the Set for one shape which
save the Name of the shape, and the 2nd shape is currently selected. How can
I group the currently selected shape with the shape I set with the Set
command???

Looking below, How do I group vsoUnitR and vsoUnitD together with VBA code?
Note that vsoUnitD currently is selected.


Your help is deeply appreciated !!

Thanks,

Gary

P.S. Below is part of my code:

Dim AppVisio As Visio.Application
Dim DocObj As Visio.Document
Dim vsoUnitR As Visio.Shape, vsoUnitD As Visio.Shape

AppVisio.Application.Documents.OpenEx Stencil_RPath, visOpenRO +
visOpenDocked
AppVisio.Application.ActiveWindow.Page.Drop
AppVisio.Application.Documents.Item(Stencil_RPath).Masters.ItemU(PR), xp, yp

Set vsoUnitR = AppVisio.Application.ActiveWindow.Selection(1)

AppVisio.Application.ActiveWindow.Selection(1).Cells("piny") = Y0 -
UnitDepth * (PosDepth - 1)
AppVisio.Application.ActiveWindow.Page.DrawLine xp, Y0, xp, Y0 -
UnitDepth * (PosDepth - 1)

Set vsoUnitD = AppVisio.Application.ActiveWindow.Selection(1)
 
J

JuneTheSecond

Selection.AddToGroup method might be a way.
An example might be fiund in the help document.
But it is a bit complicated, more simple way might be
Select each and group like,,,
Set shp2 = ActiveWindow.Selection(1)
Set shp1 = ActivePage.Shapes("name")

ActiveWindow.Select shp1, visSelect
ActiveWindow.Selection.Group
 
C

Chris Roth [MVP]

Hi Gary,

I whipped up this sample before thoroughly reading your post. Maybe it will
be educational nonetheless : )

Sub Group2()

Dim shp1 As Visio.Shape, shp2 As Visio.Shape, shpGroup As Visio.Shape
Dim sel As Visio.Selection

Set sel = Visio.ActivePage.CreateSelection(visSelTypeEmpty)

'// The active page must have two shapes, with names 'Al'
'// and 'John' If not, you'll have problems!
Set shp1 = Visio.ActivePage.Shapes("Al")
Set shp2 = Visio.ActivePage.Shapes("John")

'// Select the two shapes:
Call sel.Select(shp1, Visio.VisSelectArgs.visSelect)
Call sel.Select(shp2, Visio.VisSelectArgs.visSelect)

'// Group the selection:
Set shpGroup = sel.Group

'// Examine the new group:
Debug.Print (shpGroup.Shapes(1).Name)
Debug.Print (shpGroup.Shapes(2).Name)

End Sub


--
Hope this helps,

Chris Roth
Visio MVP

Free Visio shapes:
http://www.visguy.com/category/shapes
Visio programming info:
http://www.visguy.com/category/programming/
Other Visio resources:
http://www.visguy.com/visio-links/
 
G

Gary

Thank You All !!!

I got it to work. The problem was that I was using a shape object inside
Shapes().
Once I put the name part in, it works !!!!


Gary
 

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