If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Objects within Groups
Hi
I want to write a macro that has the capability of taking a selected group, and highlighting every connection and shape within the group + their connections. I know how to find connections for a selected object, but can anyone tell me how to find objects within a group in VBA? |
#3
|
|||
|
|||
Objects within Groups
Hi Paul.
I would like to select a group, and then run a macro that hides everything in the drawing except the group I selected and everything it's children-shapes connect to (+their connections). I am having trouble with the code you gave. For example, the name of the group is "Sheet.675". Would the code be "Sheet.675.Shapes.Count"? I tried that and an error message came up, saying "Compile Error: Expected end of statement", and highlighting the period between 675 and Shapes. |
#4
|
|||
|
|||
Objects within Groups
wrote in message
... Hi Paul. I would like to select a group, and then run a macro that hides everything in the drawing except the group I selected and everything it's children-shapes connect to (+their connections). I am having trouble with the code you gave. For example, the name of the group is "Sheet.675". Would the code be "Sheet.675.Shapes.Count"? I tried that and an error message came up, saying "Compile Error: Expected end of statement", and highlighting the period between 675 and Shapes. You would use something like Debug.Print ActivePage.Shapes("Sheet.675").Shapes.Count If you are going to work with that shape, a better approach would be dim shp as visio.shape set shp = ActivePage.Shapes("Sheet.675") debug.print shp.Shapes.Count Since you are using a selection, this form may be preferable set shp = ActiveWindow.Selection(1) This will select the first shape in the selection list I would also suggest looking at layers rather than playing with the actual shapes. Use the layer to control what shapes are visible. John... Visio MVP |
#5
|
|||
|
|||
Objects within Groups
Hi John, thanks for the help. I can use the piece of code you gave me
to find the count, so I know it works. One thing that is still confusing me is how to loop through the group members. I've got the following: Dim cmd As Visio.Shape Dim mem As Visio.Shape Dim con As Visio.Connects Debug.Print cmd.Shapes.Count Set cmd = ActivePage.Shapes("Sheet.675") For Each shp in cmd Set con = shp.Connects Next shp --- I am getting compilation errors. I thought setting the group variable to a Visio.Shapes type would make more sense seeing as how there are multiple shapes, but when I did that it wouldn't even let me do the debug.print. Do you know any possible sources for the error? |
#6
|
|||
|
|||
Objects within Groups
On Thu, 22 Jan 2009 08:31:17 -0800 (PST),
wrote: Hi John, thanks for the help. I can use the piece of code you gave me to find the count, so I know it works. One thing that is still confusing me is how to loop through the group members. I've got the following: Dim cmd As Visio.Shape Dim mem As Visio.Shape Dim con As Visio.Connects Debug.Print cmd.Shapes.Count Set cmd = ActivePage.Shapes("Sheet.675") For Each shp in cmd Set con = shp.Connects Next shp --- I am getting compilation errors. I thought setting the group variable to a Visio.Shapes type would make more sense seeing as how there are multiple shapes, but when I did that it wouldn't even let me do the debug.print. Do you know any possible sources for the error? What's the compilation error? Dim shp as Visio.Shape -- Regards, Paul Herber, Sandrila Ltd. Electronics Packages for Visio http://www.electronics-packages.sandrila.co.uk/ |
#7
|
|||
|
|||
Objects within Groups
wrote in message
... Hi John, thanks for the help. I can use the piece of code you gave me to find the count, so I know it works. One thing that is still confusing me is how to loop through the group members. I've got the following: Dim cmd As Visio.Shape Dim mem As Visio.Shape Dim con As Visio.Connects Debug.Print cmd.Shapes.Count Set cmd = ActivePage.Shapes("Sheet.675") For Each shp in cmd Set con = shp.Connects Next shp --- I am getting compilation errors. I thought setting the group variable to a Visio.Shapes type would make more sense seeing as how there are multiple shapes, but when I did that it wouldn't even let me do the debug.print. Do you know any possible sources for the error? cmd is a shapes collection so should be dim'd as Visio.Shapes Since Shapes can contain shapes you will have to add a touch of recursion. Public Sub ConnectionsList() Dim vsoSelect As Visio.Selection Dim vsoShape As Visio.Shape Dim vsoShapes As Visio.Shapes Set vsoSelect = Visio.ActiveWindow.Selection Debug.Print vsoSelect.Count If vsoSelect.Count 0 Then 'For each shape in the selection, get its connections. For Each vsoShape In vsoSelect Call ProcessShape(shp) Next vsoShape Else MsgBox "You Must Have Something Selected" End If End Sub Public Sub ProcessShape(shp As Visio.Shape) Dim subshp As Visio.Shape Dim vsoConnect As Visio.Connect Dim vsoConnects As Visio.Connects Debug.Print shp.Name Set vsoConnects = vsoShape.Connects 'For each connection, get the shape it connects to. For Each vsoConnect In vsoConnects 'Print the name of the shape the 'Connect object connects to. Debug.Print vsoShape.Name; " connects to "; vsoConnect.ToSheet.Name Next vsoConnect If shp.Shapes.Count 0 Then For Each subshp In shp.Shapes Call ProcessShape(subshp ) Next subshp End If End Sub John... Visio MVP |
#8
|
|||
|
|||
Objects within Groups
"Paul Herber" wrote in message
ell.net... On Thu, 22 Jan 2009 08:31:17 -0800 (PST), wrote: Hi John, thanks for the help. I can use the piece of code you gave me to find the count, so I know it works. One thing that is still confusing me is how to loop through the group members. I've got the following: Dim cmd As Visio.Shape Dim mem As Visio.Shape Dim con As Visio.Connects Debug.Print cmd.Shapes.Count Set cmd = ActivePage.Shapes("Sheet.675") For Each shp in cmd Set con = shp.Connects Next shp --- I am getting compilation errors. I thought setting the group variable to a Visio.Shapes type would make more sense seeing as how there are multiple shapes, but when I did that it wouldn't even let me do the debug.print. Do you know any possible sources for the error? What's the compilation error? Dim shp as Visio.Shape Regards, Paul Herber, Sandrila Ltd. Electronics Packages for Visio http://www.electronics-packages.sandrila.co.uk/ I was a bit quick on the trigger. From the SET line, cmd is a single shape and he is trying to do a "For Each" on it. the line should be For each shp in cmd.shapes John... Visio MVP |
#9
|
|||
|
|||
Objects within Groups
Dim cmd As Visio.Shape(s)
Dim mem As Visio.Shape Set cmd = ActivePage.Shapes("Sheet.675") Debug.Print cmd.Shapes.Count --- This only works when cmd is a Visio.Shape, does not compile when it is Visio.Shapes. However, I can't loop through them since it is a shape not a shapes. Should it be a Visio.Selection? It is not a selection, it is a group. Does that make any difference then? Because I tried the code you wrote and it didnt compile ("ByRef argument type mismatch"). I'm just trying to get back to basics, I'll forget about the connections for now since I'm pretty sure I know how to do that. I just need to figure out a way to loop through the member shapes in a group, so I can add them to a layer to make them visible I guess. I know the logic, it's just a matter of choosing the right variable type I just can't figure it out. Thanks for your help so far! |
#10
|
|||
|
|||
Objects within Groups
wrote in message
... Dim cmd As Visio.Shape(s) Dim mem As Visio.Shape Set cmd = ActivePage.Shapes("Sheet.675") Debug.Print cmd.Shapes.Count --- This only works when cmd is a Visio.Shape, does not compile when it is Visio.Shapes. However, I can't loop through them since it is a shape not a shapes. Should it be a Visio.Selection? It is not a selection, it is a group. Does that make any difference then? Because I tried the code you wrote and it didnt compile ("ByRef argument type mismatch"). I'm just trying to get back to basics, I'll forget about the connections for now since I'm pretty sure I know how to do that. I just need to figure out a way to loop through the member shapes in a group, so I can add them to a layer to make them visible I guess. I know the logic, it's just a matter of choosing the right variable type I just can't figure it out. Thanks for your help so far! That was my mistake. Do not change the Dim of cmd. You need to use For Each shp in cmd.Shapes instead of For Each shp in cmd That was why I thought cmd should be Visio.shapes, but in the "Set cmd =" is properly used as a Visio.Shape. The other answer is a full example John... Visio MVP |
|
Thread Tools | |
Display Modes | |
|
|