Table of contents
Collapse the table of content
Expand the table of content

Window.SelectedMasters Property (Visio)

office 365 dev account|Last Updated: 6/12/2017
1 Contributor

Returns an array of the masters or master shortcuts selected in a Microsoft Visio stencil window. Read-only.


expression . SelectedMasters

expression A variable that represents a Window object.

Return Value



The SelectedMasters property applies only to stencil windows. If you try to access the SelectedMasters property for other types of window, Visio might return an error.


This Microsoft Visual Basic for Applications (VBA) macro uses the SelectedMasters property to get the number of masters and master shortcuts selected in a stencil window and then prints the name of the stencil and the selected masters and master shortcuts in the Immediate window.

Before running this macro, make sure that at least one master or master shortcut is selected in a docked stencil in the active Visio window.

Sub SelectedMasters_Example() 

 Dim vsoWindow As Visio.Window 
 Dim aobjSelectedMasters() As Object 
 Dim intNumberMasters As Integer 
 Dim intNumberMasterShortCuts As Integer 
 Dim vsoMaster As Visio.Master 
 Dim vsoMasterShortcut As Visio.MasterShortcut 
 intNumberMaster = 0 
 intNumberMasterShortCuts = 0 

 For Each vsoWindow In ActiveWindow.Windows 

 If (vsoWindow.Type = visDockedStencilBuiltIn) Then 
 aobjSelectedMasters = vsoWindow.SelectedMasters 

 For intCounter = LBound(aobjSelectedMasters) To UBound(aobjSelectedMasters) 
 On Error Resume Next 
 Set vsoMaster = Nothing 
 Set vsoMasterShortcut = Nothing 
 Set vsoMaster = aobjSelectedMasters(intCounter) 

 If Not vsoMaster Is Nothing Then 
 intNumberMasters = intNumberMasters + 1 
 Set vsoMasterShortcut = aobjSelectedMasters(intCounter) 

 If Not vsoMasterShortcut Is Nothing Then 
 intNumberMasterShortCuts = intNumberMasterShortCuts + 1 
 End If 

 End If 


 If (intNumberMasters > 0 Or intNumberMasterShortCuts > 0) Then 
 Debug.Print "The stencil " &; vsoWindow.Document.Name 
 Debug.Print "has" &; Str(intNumberMasters) &; " masters selected and " 
 Debug.Print Str(intNumberMasterShortCuts) &; " master shortcuts selected." 
 Exit For 
 End If 

 End If 


End Sub
© 2018 Microsoft