A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Powerpoint, Publisher and Visio » Visio
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Objects within Groups



 
 
Thread Tools Display Modes
  #1  
Old January 21st, 2009, 01:00 PM posted to microsoft.public.visio.general
[email protected]
external usenet poster
 
Posts: 32
Default 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  
Old January 22nd, 2009, 02:08 PM posted to microsoft.public.visio.general
[email protected]
external usenet poster
 
Posts: 32
Default 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  
Old January 22nd, 2009, 03:06 PM posted to microsoft.public.visio.general
John... Visio MVP
external usenet poster
 
Posts: 900
Default 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  
Old January 22nd, 2009, 04:31 PM posted to microsoft.public.visio.general
[email protected]
external usenet poster
 
Posts: 32
Default 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?
  #7  
Old January 22nd, 2009, 05:07 PM posted to microsoft.public.visio.general
John... Visio MVP
external usenet poster
 
Posts: 900
Default 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

  #9  
Old January 22nd, 2009, 06:35 PM posted to microsoft.public.visio.general
[email protected]
external usenet poster
 
Posts: 32
Default 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  
Old January 22nd, 2009, 10:02 PM posted to microsoft.public.visio.general
John... Visio MVP
external usenet poster
 
Posts: 900
Default 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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 04:35 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.