我正在尝试制作一个Visio宏,该宏将按字母顺序排列文档中第一个停靠的模具中的母版。下面是我的代码。但是,设置vsoDoc = Visio.Documents.ItemFromID(0)似乎不是引用停靠的模具,而是引用文档模具。如何获得对接的模具?任何帮助,不胜感激!
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
我希望制作一个新模板,其母版与停靠的模板相同,但按字母顺序排列。但是,产生的新模具是从按字母顺序排列的文档模具中产生的。 Visio.Documents.ItemFromID(0)返回文档模具,但我想获得第一个停靠的模具。如何获得对接的模具?
答案 0 :(得分:0)
您可以遍历ActiveWindow.Windows列表并找到任何其.Type = visDockedStencilBuiltIn的窗口,也可以按.Document.Name进行查找,我认为您可以通过检查(.WindowState而visWSActive)= True
因此,基本上,它的工作方式不是将模板真正附加到您的文档,而是显示文档的窗口。因此,您必须查看在文档窗口中打开了哪些子窗口,每个子窗口中都可以有一个关联的文档(模具)
答案 1 :(得分:0)
解决了!通过用下面的代码替换vsoDoc变量的赋值,我得到了预期的结果。
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