我在Visio 2016中创建了自定义颜色集,但无法从宏访问它。甚至下面的 recorded 宏也会出现以下错误:
Run-time error '-2032465751 (86db08a9)':
Invalid parameter.
调试器突出显示其中包含65535的行。有什么想法如何使用宏实现这一目标吗?谢谢!
Sub Macro3()
'Enable diagram services
Dim DiagramServices As Integer
DiagramServices = ActiveDocument.DiagramServicesEnabled
ActiveDocument.DiagramServicesEnabled = visServiceVersion140 + visServiceVersion150
ActivePage.SetTheme 33, 33, 33, 33, 33
ActivePage.SetTheme ActivePage.GetTheme(visThemeTypeIndex), 65535, ActivePage.GetTheme(visThemeTypeEffect), ActivePage.GetTheme(visThemeTypeConnector), ActivePage.GetTheme(visThemeTypeFont)
'Restore diagram services
ActiveDocument.DiagramServicesEnabled = DiagramServices
End Sub
更新 这是其他人的工作代码示例。使用PrintMasterGuids查找GUID(大括号中的数字)。
Public Sub PrintMasterGuids()
'// Use this to find the master GUID for a custom color variant.
Dim mst As Master
Dim vDoc As Document
'Change ThisDocument to the target if you're
'not running the code from the same place
Set vDoc = ThisDocument
For Each mst In vDoc.Masters
Debug.Print mst.NameU, mst.UniqueID
Next
End Sub
Sub Theme_Office_with_Custom_colors()
'Enable diagram services
Dim DiagramServices As Integer
DiagramServices = ActiveDocument.DiagramServicesEnabled
ActiveDocument.DiagramServicesEnabled = visServiceVersion140 + visServiceVersion150
Dim UndoScopeID1 As Long
UndoScopeID1 = Application.BeginUndoScope("Apply Theme to Document")
Dim doc As Visio.Document
Set doc = Visio.ActiveDocument
'// Loop through pages:
For Each pg In doc.Pages
'// Office theme
pg.SetTheme 33, 33, 33, 33, 33
'// Apply the Custom colors
Dim UndoScopeID2 As Long
UndoScopeID2 = Application.BeginUndoScope("Apply Theme Variant")
pg.PageSheet.CellsU("ColorSchemeIndex").FormulaU = "=USE({76B4C447-0406-0000-8E40-00608CF305B2})*0+65535"
Application.EndUndoScope UndoScopeID2, True
Next
Application.EndUndoScope UndoScopeID1, True
'Restore diagram services
ActiveDocument.DiagramServicesEnabled = DiagramServices
End Sub
答案 0 :(得分:0)
据我所知,您不能直接在api中使用自定义颜色集,因此您必须直接定位并寻址相关单元格。
创建自定义颜色集时,Visio将创建一个单独的(隐藏的)母版来存储RGB。该主机已分配了GUID,您必须在USE
单元格的ColorSchemeIndex
函数内使用它。
因此在您的代码中,如果您唯一要更改的是颜色单元,则可以执行以下操作:
ActivePage.PageSheet.CellsU("ColorSchemeIndex").FormulaU = "=USE({007C1AB0-0002-0000-8E40-00608CF305B2})*0+65535"
...其中GUID是对母版的引用。
首先要掌握GUID,只需将自定义颜色设置应用于页面,然后检查ColorSchemeIndex
单元格公式,或者,您可以循环浏览文档中的母版并报告。此处描述的UniqueID属性:http://visualsignals.typepad.co.uk/vislog/2013/10/customizing-themes-in-visio-2013.html