Reputation: 3
I am attempting to make a Visio macro which will alphabetize the masters in the first docked stencil in a document. Below is my code. However, Set vsoDoc = Visio.Documents.ItemFromID(0) does not appear to reference the docked stencil, but the document stencil. How do I get the docked stencil? Any help much appreciated!
Dim i As Integer
Dim vsoDoc As Visio.Document
Dim vsoDocNew As Visio.Document
Dim dictMasters As New Scripting.Dictionary
Set vsoDoc = Visio.Documents.ItemFromID(0) 'Existing Stencil
Set vsoDocNew = Visio.Documents.AddEx("New Stencil.vss", , visAddStencil) 'New Sorted Stencil
'Get the names of the existing masters and sort them
For i = 1 To vsoDoc.Masters.Count
Call dictMasters.Add(vsoDoc.Masters(i).Name, vsoDoc.Masters(i))
Next
list = dictMasters.Keys()
Dim First As Integer, Last As Long
Dim x As Long, j As Long
Dim Temp As String
First = LBound(list)
Last = UBound(list)
For x = First To Last - 1
For j = x + 1 To Last
If list(x) > list(j) Then
Temp = list(j)
list(j) = list(x)
list(x) = Temp
End If
Next j
Next x
'Drop the existing masters into the new stencil based on the sorting
For i = 1 To dictMasters.Count
Call vsoDocNew.Masters.Drop(dictMasters(list(i - 1)), 0, 0)
Next
I am hoping to produce a new stencil with the same masters as the docked stencil but alphabetized. However, the new stencil produced is from alphabetizing the document stencil. Visio.Documents.ItemFromID(0) is returning the document stencil, but I want to get the first docked stencil. How to I get the docked stencil?
Upvotes: 0
Views: 601
Reputation: 3
Solved! By replacing the assignment of the vsoDoc variable with the below code, I got the desired result.
For i = 1 To ActiveWindow.windows.Count
If ActiveWindow.windows(i).Type = visDockedStencilBuiltIn Then
Debug.Print ActiveWindow.windows(i).Document.Name
Set vsoDoc = ActiveWindow.windows(i).Document
Debug.Print vsoDoc.Name
End If
Next
Upvotes: 0
Reputation: 4327
You can loop through the ActiveWindow.Windows list and find any window whose .Type = visDockedStencilBuiltIn or you can go by the .Document.Name, and I think you can check whether the stencil is in front by checking if (.WindowState And visWSActive) = True
So basically the way it works, the stencils aren't really attached to your document, but rather the Window in which the document is displayed. So you have to see what sub-windows are open in your document's window, where each sub-window can have an associated document (the stencil)
Upvotes: 1