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  

Using Selection



 
 
Thread Tools Display Modes
  #1  
Old January 15th, 2009, 04:16 PM posted to microsoft.public.visio.general
Sachin[_2_]
external usenet poster
 
Posts: 15
Default Using Selection

Hi everyone. I want to create a macro that takes currently selected
objects and somehow sets them (and their connectors and connected
shapes) apart from the rest of the drawing. I am familiar with these
two pieces of code from John Marshall's site:

----
Dim VsoSelect As Visio.Selection
Dim VsoShape as Visio.Shape

Set VsoSelect = Visio.ActiveWindow.Selection

If VsoSelect.Count 0 Then
for each VsoShape in VsoSelect

next VsoShape
else
MsgBox "You Must Have Something Selected"
end if
---
Dim vsoShapes As Visio.Shapes
Dim vsoShape As Visio.Shape
Dim vsoConnectTo As Visio.Shape
Dim vsoConnects As Visio.Connects
Dim vsoConnect As Visio.Connect
Dim intCurrentShapeIndex As Integer
Dim intCounter As Integer
Set vsoShapes = ActivePage.Shapes

'For each shape on the page, get its connections.
For intCurrentShapeIndex = 1 To vsoShapes.Count

Set vsoShape = vsoShapes(intCurrentShapeIndex)
Set vsoConnects = vsoShape.Connects

'For each connection, get the shape it connects to.
For intCounter = 1 To vsoConnects.Count

Set vsoConnect = vsoConnects(intCounter)
Set vsoConnectTo = vsoConnect.ToSheet

'Print the name of the shape the
'Connect object connects to.
Debug.Print vsoConnectTo.Name

Next intCounter

Next intCurrentShapeIndex
---

I know that within these sub procedures lies my answer and I am trying
to combine them somehow. What made sense to me was to do this:

Set vsoSelect = Visio.ActiveWindow.selection
Set vsoShape = vsoSelect
Set vsoConnects = vsoShape.Connects

But it's giving me a type mismatch error. Does anyone have any other
ideas?

Thanks
  #2  
Old January 15th, 2009, 04:29 PM posted to microsoft.public.visio.general
Paul Herber
external usenet poster
 
Posts: 1,732
Default Using Selection

On Thu, 15 Jan 2009 08:16:33 -0800 (PST), Sachin
wrote:

Set vsoSelect = Visio.ActiveWindow.selection
Set vsoShape = vsoSelect


Set vsoShapes = vsoSelect


--

Regards, Paul Herber, Sandrila Ltd.
Electronics Packages for Visio http://www.electronics-packages.sandrila.co.uk/
  #3  
Old January 15th, 2009, 04:40 PM posted to microsoft.public.visio.general
Sachin[_2_]
external usenet poster
 
Posts: 15
Default Using Selection

Set vsoSelect = Visio.ActiveWindow.selection
Set vsoShapes = vsoSelect
Set vsoConnects = vsoShapes.Connects


Thanks, but still giving me a type mismatch at my third line. I don't
understand why, though. vsoShapes is set to a selection of shapes, so
the type should be correct, should it not?
  #4  
Old January 15th, 2009, 05:29 PM posted to microsoft.public.visio.general
Paul Herber
external usenet poster
 
Posts: 1,732
Default Using Selection

On Thu, 15 Jan 2009 08:40:17 -0800 (PST), Sachin
wrote:

Set vsoSelect = Visio.ActiveWindow.selection
Set vsoShapes = vsoSelect
Set vsoConnects = vsoShapes.Connects


Thanks, but still giving me a type mismatch at my third line. I don't
understand why, though. vsoShapes is set to a selection of shapes, so
the type should be correct, should it not?


You can only refer to one shape's connects at a time
Set vsoConnects = vsoShape.Connects


--

Regards, Paul Herber, Sandrila Ltd.
Electronics for Visio http://www.electronics.sandrila.co.uk/
  #5  
Old January 15th, 2009, 06:11 PM posted to microsoft.public.visio.general
Sachin[_2_]
external usenet poster
 
Posts: 15
Default Using Selection

I'm still getting the same error. I think it has something to do an
inability to take connects from a selection without the proper
bridging syntax?
  #6  
Old January 15th, 2009, 06:17 PM posted to microsoft.public.visio.general
Paul Herber
external usenet poster
 
Posts: 1,732
Default Using Selection

On Thu, 15 Jan 2009 10:11:49 -0800 (PST), Sachin
wrote:

I'm still getting the same error. I think it has something to do an
inability to take connects from a selection without the proper
bridging syntax?


No, the connects belong to a shape, Iterate through the sahpes in a
selection, then get the connects for each shape.


--
Regards, Paul Herber, Sandrila Ltd.
Electrical for Visio http://www.electrical.sandrila.co.uk/
  #7  
Old January 15th, 2009, 06:31 PM posted to microsoft.public.visio.general
Sachin[_2_]
external usenet poster
 
Posts: 15
Default Using Selection

the connects belong to a shape

Exactly.

The connections belong to a shape, the shape belongs to a selection. I
need to get the connections of a selection, so to do so I used the
bridge: Set vsoShape = vsoSelect, where vsoSelect is = to the
selection. Then I tried getting the connections from vsoShape. But
it's giving me the mismatch error which leads me to believe that the
bridge is wrong, it is trying to get connections from a selection
which is probably a mismatch. And I am hard coding for one shape only
for simplicity and to avoid confusion.

I am very confused.
  #8  
Old January 15th, 2009, 10:48 PM posted to microsoft.public.visio.general
John... Visio MVP
external usenet poster
 
Posts: 900
Default Using Selection

I have simplified the code, so this should be what you are looking for:

Public Sub ListConnections()

Dim vsoConnect As Visio.Connect
Dim vsoConnects As Visio.Connects
Dim vsoSelect As Visio.Selection
Dim vsoShape As Visio.Shape
Dim vsoShapes As Visio.Shapes

Set vsoSelect = Visio.ActiveWindow.Selection

If vsoSelect.Count 0 Then
'For each shape in the selection, get its connections.
For Each vsoShape In vsoSelect

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 vsoConnect.ToSheet.Name; " Connects to ";
vsoConnect.FromSheet.Name

Next vsoConnect

Next vsoShape
Else
MsgBox "You Must Have Something Selected"
End If

End Sub

"Sachin" wrote in message
...
Hi everyone. I want to create a macro that takes currently selected
objects and somehow sets them (and their connectors and connected
shapes) apart from the rest of the drawing. I am familiar with these
two pieces of code from John Marshall's site:

----
Dim VsoSelect As Visio.Selection
Dim VsoShape as Visio.Shape

Set VsoSelect = Visio.ActiveWindow.Selection

If VsoSelect.Count 0 Then
for each VsoShape in VsoSelect

next VsoShape
else
MsgBox "You Must Have Something Selected"
end if
---
Dim vsoShapes As Visio.Shapes
Dim vsoShape As Visio.Shape
Dim vsoConnectTo As Visio.Shape
Dim vsoConnects As Visio.Connects
Dim vsoConnect As Visio.Connect
Dim intCurrentShapeIndex As Integer
Dim intCounter As Integer
Set vsoShapes = ActivePage.Shapes

'For each shape on the page, get its connections.
For intCurrentShapeIndex = 1 To vsoShapes.Count

Set vsoShape = vsoShapes(intCurrentShapeIndex)
Set vsoConnects = vsoShape.Connects

'For each connection, get the shape it connects to.
For intCounter = 1 To vsoConnects.Count

Set vsoConnect = vsoConnects(intCounter)
Set vsoConnectTo = vsoConnect.ToSheet

'Print the name of the shape the
'Connect object connects to.
Debug.Print vsoConnectTo.Name

Next intCounter

Next intCurrentShapeIndex
---

I know that within these sub procedures lies my answer and I am trying
to combine them somehow. What made sense to me was to do this:

Set vsoSelect = Visio.ActiveWindow.selection
Set vsoShape = vsoSelect
Set vsoConnects = vsoShape.Connects

But it's giving me a type mismatch error. Does anyone have any other
ideas?

Thanks



  #9  
Old January 15th, 2009, 11:50 PM posted to microsoft.public.visio.general
John... Visio MVP
external usenet poster
 
Posts: 900
Default Using Selection

Two more point, each shape has two connection collections. Connects lists
the shapes the shape is connected to and FromConnects lists the shapes that
connect to this shape.
So if you want to list ALL connections you need to check both collections. I
have attached an updated procedure that shows this at the end of this
message

The second point is that if you have two boxes with a connection lines, the
boxes are not really connected to each other. Each box is connected to the
connector which is then connected to the other box. So if you need to
abstract to Box A connected to Box B you need to do a lot of checking.

Public Sub ListConnections()

Dim vsoConnect As Visio.Connect
Dim vsoConnects As Visio.Connects
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

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

Set vsoConnects = vsoShape.FromConnects

'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; " is connected from ";
vsoConnect.FromSheet.Name

Next vsoConnect


Next vsoShape
Else
MsgBox "You Must Have Something Selected"
End If

End Sub


"Sachin" wrote in message
...
Hi everyone. I want to create a macro that takes currently selected
objects and somehow sets them (and their connectors and connected
shapes) apart from the rest of the drawing. I am familiar with these
two pieces of code from John Marshall's site:

----
Dim VsoSelect As Visio.Selection
Dim VsoShape as Visio.Shape

Set VsoSelect = Visio.ActiveWindow.Selection

If VsoSelect.Count 0 Then
for each VsoShape in VsoSelect

next VsoShape
else
MsgBox "You Must Have Something Selected"
end if
---
Dim vsoShapes As Visio.Shapes
Dim vsoShape As Visio.Shape
Dim vsoConnectTo As Visio.Shape
Dim vsoConnects As Visio.Connects
Dim vsoConnect As Visio.Connect
Dim intCurrentShapeIndex As Integer
Dim intCounter As Integer
Set vsoShapes = ActivePage.Shapes

'For each shape on the page, get its connections.
For intCurrentShapeIndex = 1 To vsoShapes.Count

Set vsoShape = vsoShapes(intCurrentShapeIndex)
Set vsoConnects = vsoShape.Connects

'For each connection, get the shape it connects to.
For intCounter = 1 To vsoConnects.Count

Set vsoConnect = vsoConnects(intCounter)
Set vsoConnectTo = vsoConnect.ToSheet

'Print the name of the shape the
'Connect object connects to.
Debug.Print vsoConnectTo.Name

Next intCounter

Next intCurrentShapeIndex
---

I know that within these sub procedures lies my answer and I am trying
to combine them somehow. What made sense to me was to do this:

Set vsoSelect = Visio.ActiveWindow.selection
Set vsoShape = vsoSelect
Set vsoConnects = vsoShape.Connects

But it's giving me a type mismatch error. Does anyone have any other
ideas?

Thanks





  #10  
Old January 16th, 2009, 01:01 AM posted to microsoft.public.visio.general
Paul Herber
external usenet poster
 
Posts: 1,732
Default Using Selection

On Thu, 15 Jan 2009 10:31:07 -0800 (PST), Sachin
wrote:

the connects belong to a shape


Exactly.

The connections belong to a shape, the shape belongs to a selection. I
need to get the connections of a selection, so to do so I used the
bridge


No such thing as a bridge.
Look at the code John has posted
1. create a reference to the selection
2. this selection contains selection.count shapes
3. loop though these shapes using for each
4. with each shape get the connects


--
Regards, Paul Herber, Sandrila Ltd.
DFD/SSADM for Visio http://www.visio-dfd.sandrila.co.uk/
 




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:30 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.