How to get handle on selected item in a stencil

Started by goldnhue, April 26, 2011, 04:00:40 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

goldnhue

I want to modify the currently selected item in a stencil, but I don't know the name of the item or stencil.  The only way the item is identified is because it is selected.  How do I get a handle on that item?

Thank you.

Visio Guy

Hi GnH,

Try the window.SelectedMasters property.

And be sure to read this article, if you haven't already:

Edit Visio Masters Programmatically...the Right Way!
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

goldnhue

Thank you, that did it.  Here is code that worked for me incase anyone else needs to modify selected stencil item without knowing stencil or object name.

Public Sub AddCustomFields()
    ' Modify selected stencil object when you don't know stencil or object names
    ' Also see: http://msdn.microsoft.com/en-us/library/ff767298.aspx
 
    Dim VN As String, shpObj As Visio.shape
    Dim mstObj As Visio.Master, mstObjCopy As Visio.Master
    Dim shpsObj As Visio.Shapes
    Dim StnObj As Visio.Document
    Dim curShapeIndx As Integer
    Dim vsoWindow As Visio.Window
    Dim strMsg As String     
    Dim aobjSelectedMasters() As Object
    Dim intNumberMasters As Integer
    Dim vsoMaster As Visio.Master
    intNumberMasters = 0

    For Each vsoWindow In ActiveWindow.Windows
        If (vsoWindow.Type = visDockedStencilBuiltIn) Then
            Set StnObj = ThisDocument.Application.Documents(vsoWindow.Document.Name)
            aobjSelectedMasters = vsoWindow.SelectedMasters
             
              For intCounter = LBound(aobjSelectedMasters) To UBound(aobjSelectedMasters)
                On Error Resume Next
                Set vsoMaster = Nothing
                Set vsoMaster = aobjSelectedMasters(intCounter)

                If Not vsoMaster Is Nothing Then
                    intNumberMasters = intNumberMasters + 1
                    Set mstObjCopy = vsoMaster.Open
                    Set shpsObj = mstObjCopy.Shapes
                    Set shpObj = shpsObj(1)

                    ' call routine to modify the shape as desired here ....
                   
                    mstObjCopy.Close
               
                End If
            Next
           
            If (intNumberMasters > 0) Then
'                Debug.Print "The stencil " & vsoWindow.Document.Name
'                Debug.Print "has" & Str(intNumberMasters) & " masters selected "
                Exit For
            End If
        End If
    Next
   
    ' Save the stencil object
     StnObj.Save 
'     StnObj.Close
'     Set StnObj = Nothing
     
End Sub