在Microsoft Visio下,我可以修改“功能区”菜单,但是例如当用户单击形状时,我需要即时修改值。 为了简化理解,请参见下面我完成的代码,该代码创建一个名为“ test”的新菜单,该菜单下有一个按钮。目标是单击此按钮时,它应该更改按钮的标签名称。我无法使它起作用。 请注意,我没有将回调函数放到模块上,因为我必须使用全局函数中的特定函数。
请参阅下面的代码。您可以复制/粘贴并测试它。 希望有人可以指出错误或解决方法?
Option Explicit
Dim ribbonUI As IRibbonUI
Dim loggedIn As Boolean
Public Sub CreateRibbon()
Dim ribbonXML As String
ribbonXML = "<customUI xmlns=""http://schemas.microsoft.com/office/2006/01/customui"" onLoad=""ribbonLoaded"">"
ribbonXML = ribbonXML + " <ribbon startFromScratch=""false"">"
ribbonXML = ribbonXML + " <tabs>"
ribbonXML = ribbonXML + " <tab id=""TB01"" label=""Test"">"
ribbonXML = ribbonXML + " <group id=""GR01"" label=""Test Labelling"">"
ribbonXML = ribbonXML + " <button id=""Login"" getLabel=""ThisDocument.getLabelLogin"" size=""large"" imageMso=""HappyFace"" onAction=""ThisDocument.OnActionLogin""/>"
ribbonXML = ribbonXML + " </group>"
ribbonXML = ribbonXML + " </tab>"
ribbonXML = ribbonXML + " </tabs>"
ribbonXML = ribbonXML + " </ribbon>"
ribbonXML = ribbonXML + "</customUI>"
ActiveDocument.CustomUI = ribbonXML
End Sub
Public Sub Document_DocumentOpened(ByVal doc As IVDocument)
Call CreateRibbon
End Sub
Public Sub ribbonLoaded(ribbon As IRibbonUI)
Set ribbonUI = ribbon
End Sub
Public Sub OnActionLogin(control As IRibbonControl)
If loggedIn = True Then
loggedIn = False
Else
loggedIn = True
End If
MsgBox ("you press the buttton. Value=" & loggedIn)
ribbonUI.Invalidate
End Sub
Public Sub getLabelLogin(control As IRibbonControl, ByRef returnedVal)
If loggedIn = True Then
returnedVal = "Value True"
Else
returnedVal = "Value False"
End If
MsgBox "New value=" & loggedIn & " " & control.id
End Sub
谢谢
答案 0 :(得分:1)
我发现了错误! “加载”功能从未启动。我有“ ThisDocument”。上线:
ribbonXML = "<customUI xmlns=""http://schemas.microsoft.com/office/2006/01/customui"" onLoad=""ThisDocument.ribbonLoaded"">"