Visio:从宏访问自定义颜色变体?

Visio: Accessing Custom Color Variant from macro?

我在 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

据我所知,您不能直接通过 api 使用自定义颜色集,因此您必须向下搜索并直接处理相关单元格。

当您创建自定义颜色集时,Visio 会创建一个单独的(隐藏的)母版来存储 RGB。该母版分配了一个 GUID,您必须在 ColorSchemeIndex 单元格的 USE 函数中使用它。

所以在您的代码中,如果您唯一想要更改的是颜色单元格,那么您可以这样做:

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