Identifying currently selected Object.ID

D

David T.

I'm new to VBA in Visio and am stuggling with something very basic,
determining the object id of the currently selected object. I've seen many
examples of how to use FromItemID(x) to recover values and set properties but
I have determined how to determine what the id of my currnetly selected
object is.

The simple macro that I am starting with is to first select a box and then
run a macro to make the box line visible, bring it to the front, and enter a
value into one of the customer properties. I can do all this if I can first
determine the object index.

Any help would be appreciated,
Thanks, David
 
J

JuneTheSecond

If just one shape is selected, the ID might be objSelection(1).ID or
ActiveWindow.Selection(1).ID .
 
D

David T.

I'm trying to keep it very simple to test through syntax and so have set both
of the statements below to just a value:

varInt = objSelection(1).ID / results in invalid sub or function

varInt = ActiveWindow.Selection(1).ID / rusults in invalid selection
identifier

If I could find the right syntax and capture the ID value of what is
currently selected, there are a great many things that I could then do. I'm
suprised that there isn't a CurrentObject type function.

Thanks for the help, David.
 
J

JuneTheSecond

varInt = objSelection(1).ID / results in invalid sub or function
you should declareand define objSelection with dim ... and set
objSelection= ....
varInt = ActiveWindow.Selection(1).ID / rusults in invalid selection identifier
you should select one shape on the page of visio drawing.
 
D

David T.

Thanks for the help. I'd had the code working for some time and didn't know
it. The problem is that the objects that I am selecting with the mouse is an
item of a group and is not recognized by the Selection.

I'm still not sure how to programatically recognize the ID of a
mouse-selected item that is within a group.
 
J

JuneTheSecond

You might check IterationMode property, if you select a shape in a group.
For example;
Dim mySlection As Visio.Selection
Set mySlection = ActiveWindow.Selection
mySlection.IterationMode = visSelModeOnlySub
Debug.Print mySlection(1).ID, mySlection(1).Name
 
D

David T.

After selecting an element within a group, the following command results in 0:

MsgBox ActiveWindow.Selection.Count

After selecting a non group object or a parent object the result is 1. The
problem lies in that the Selection statement does not even see or count the
group's sub item as being selected.
 
M

Mark Nelson [MS]

June has the right answer. When working with groups you must set the
IterationMode property on the Selection object before querying it for
information.

--
Mark Nelson
Office Graphics - Visio
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
 
D

David T.

Thank you much for the help. Since I sometimes have mulitple layers of
grouping I can end up with more than one object being selected. The
following code has worked well:

Sub ActivateMyPort()
'
' Brings port to the front and set line weight to .24 pt
Dim mySelection As Visio.Selection
Dim myShape As Visio.Shape
Set mySelection = ActiveWindow.Selection

If mySelection.Count = 0 Then
mySelection.IterationMode = visSelModeOnlySub
End If

If mySelection.Count = 0 Then
MsgBox "No selection found"
Else
Set myShape = mySelection(mySelection.Count)
myShape.LineStyle = "PortFraming"
myShape.BringToFront
End If

End Sub

Again, thanks for the help.
 

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