VBA code to open shapesheet for selected shape?

M

Matt Steele

I am unable to piece together simple code that will enable me to open the
shapesheet for a selected shape. The problem is that the recorded macro
always bring in the shape ID. I do not know how to substitute the shape ID
for something generic so that when I select the next shape, I can rerun the
macro.

Any help is greatly appreciated!
Thanks.
 
M

Matt Steele

John Marshall at one point posted this. However I am too new to vba to make
sense of it. This tells me how to select the chosen shape and it appears to
loop through a collection of shapes. But I still cannot figure out the code
for openning the shapesheet for the shape. I know I have been close....


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
 
J

JuneTheSecond

The macro that opens shapesheet of a selected shape might be like this.
Sub Macro1()
ActiveWindow.Selection(1).OpenSheetWindow
End Sub
 
M

Matt Steele

Argg. That was so simple! Thanks JTS!
Just curious, but why does this need the (1)? I am certain I tried this and
similar lines of code without the (1) and failed.
Thank you again.
MS
 
J

JuneTheSecond

According to the reference in msdn, the selection object is a subset of
Shape objects for a page or master to which an operation can be applied.
That is, a selection object is like a collection that includes all selected
shapes on the visio window.
 
D

David Parker

Selection(1). is the same as Selection.PrimaryItem, and you may want to test
if there is a selection at all:

Sub Macro1()
If ActiveWindow.Selection.Count > 0 Then
ActiveWindow.Selection.PrimaryItem.OpenSheetWindow
End If
End Sub
 
M

Matt Steele

Thanks you both.
MS

David Parker said:
Selection(1). is the same as Selection.PrimaryItem, and you may want to test
if there is a selection at all:

Sub Macro1()
If ActiveWindow.Selection.Count > 0 Then
ActiveWindow.Selection.PrimaryItem.OpenSheetWindow
End If
End Sub
 

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