VBA 自定义功能区(ribbon):控件的回调过程(callback)再执行

ribbon中控件的一些回调过程(比如getLabel)在第一次加载完之后不会再此执行,

会一直使用缓存中的内容,想要重新执行这个方法,需要调用以下方法:

IRibbonUI.Invalidate

它的功能是使所有控件的缓存内容失效.并随后刷新 UI.

<customUI … OnLoad="MyAddinInitialize" …>

Dim MyRibbon As IRibbonUI 
 
Sub MyAddInInitialize(Ribbon As IRibbonUI) 
 Set MyRibbon = Ribbon 
End Sub 
 
Sub myFunction() 
 MyRibbon.Invalidate() ' Invalidates the caches of all of this add-in's controls 
End Sub

如果只是想让某个控件失效的话,可以使用

IRibbonUI.InvalidateControl

MyRibbon.InvalidateControl("control1") ' Invalidates the cache of a single control 

附:各控件的回调签名

Control                         Callback Name                   Signatures
(several controls)              getDescription                  Sub GetDescription(control As IRibbonControl, ByRef description)
(several controls)              getEnabled                      Sub GetEnabled(control As IRibbonControl, ByRef enabled)
(several controls)              getImage                        Sub GetImage(control As IRibbonControl, ByRef image)
(several controls)              getImageMso                     Sub GetImageMso(control As IRibbonControl, ByRef imageMso)
(several controls)              getLabel                        Sub GetLabel(control As IRibbonControl, ByRef label)
(several controls)              getKeytip                       Sub GetKeytip (control As IRibbonControl, ByRef label)
(several controls)              getSize                         sub GetSize(control As IRibbonControl, ByRef size)
(several controls)              getScreentip                    Sub GetScreentip(control As IRibbonControl, ByRef screentip)
(several controls)              getSupertip                     Sub GetSupertip(control As IRibbonControl, ByRef screentip)
(several controls)              getVisible                      Sub GetVisible(control As IRibbonControl, ByRef visible)
button                          getShowImage                    Sub GetShowImage (control As IRibbonControl, ByRef showImage)
button                          getShowLabel                    Sub GetShowLabel (control As IRibbonControl, ByRef showLabel)
button                          onAction – repurposed           Sub OnAction(control As IRibbonControl, byRef CancelDefault)
button                          onAction                        Sub OnAction(control As IRibbonControl)
checkBox                        getPressed                      Sub GetPressed(control As IRibbonControl, ByRef returnValue)
checkBox                        onAction                        Sub OnAction(control As IRibbonControl, pressed As Boolean)
comboBox                        getItemCount                    Sub GetItemCount(control As IRibbonControl, ByRef count)
comboBox                        getItemID                       Sub GetItemID(control As IRibbonControl, index As Integer, ByRef id)
comboBox                        getItemImage                    Sub GetItemImage(control As IRibbonControl, index As Integer, ByRef image)
comboBox                        getItemLabel                    Sub GetItemLabel(control As IRibbonControl, index As Integer, ByRef label)
comboBox                        getItemScreenTip                Sub GetItemScreenTip(control As IRibbonControl, index As Integer, ByRef screentip)
comboBox                        getItemSuperTip                 Sub GetItemSuperTip (control As IRibbonControl, index As Integer, ByRef supertip)
comboBox                        getText                         Sub GetText(control As IRibbonControl, ByRef text)
comboBox                        onChange                        Sub OnChange(control As IRibbonControl, text As String)
customUI                        loadImage                       Sub LoadImage(imageId As string, ByRef image)
customUI                        onLoad                          Sub OnLoad(ribbon As IRibbonUI)
dropDown                        getItemCount                    Sub GetItemCount(control As IRibbonControl, ByRef count)
dropDown                        getItemID                       Sub GetItemID(control As IRibbonControl, index As Integer, ByRef id)
dropDown                        getItemImage                    Sub GetItemImage(control As IRibbonControl, index As Integer, ByRef image)
dropDown                        getItemLabel                    Sub GetItemLabel(control As IRibbonControl, index As Integer, ByRef label)
dropDown                        getItemScreenTip                Sub GetItemScreenTip(control As IRibbonControl, index As Integer, ByRef screenTip)
dropDown                        getItemSuperTip                 Sub GetItemSuperTip (control As IRibbonControl, index As Integer, ByRef superTip)
dropDown                        getSelectedItemID               Sub GetSelectedItemID(control As IRibbonControl, ByRef index)
dropDown                        getSelectedItemIndex            Sub GetSelectedItemIndex(control As IRibbonControl, ByRef index)
dropDown                        onAction                        Sub OnAction(control As IRibbonControl, selectedId As String, selectedIndex As Integer)
dynamicMenu                     getContent                      Sub GetContent(control As IRibbonControl, ByRef content)
editBox                         getText                         Sub GetText(control As IRibbonControl, ByRef text)
editBox                         onChange                        Sub OnChange(control As IRibbonControl, text As String)
gallery                         getItemCount                    Sub GetItemCount(control As IRibbonControl, ByRef count)
gallery                         getItemHeight                   Sub getItemHeight(control As IRibbonControl, ByRef height)
gallery                         getItemID                       Sub GetItemID(control As IRibbonControl, index As Integer, ByRef id)
gallery                         getItemImage                    Sub GetItemImage(control As IRibbonControl, index As Integer, ByRef image)
gallery                         getItemLabel                    Sub GetItemLabel(control As IRibbonControl, index As Integer, ByRef label)
gallery                         getItemScreenTip                Sub GetItemScreenTip(control As IRibbonControl, index as Integer, ByRef screen)
gallery                         getItemSuperTip                 Sub GetItemSuperTip (control As IRibbonControl, index as Integer, ByRef screen)
gallery                         getItemWidth                    Sub getItemWidth(control As IRibbonControl, ByRef width)
gallery                         getSelectedItemID               Sub GetSelectedItemID(control As IRibbonControl, ByRef index)
gallery                         getSelectedItemIndex            Sub GetSelectedItemIndex(control As IRibbonControl, ByRef index)
gallery                         onAction                        Sub OnAction(control As IRibbonControl, selectedId As String, selectedIndex As Integer)
menuSeparator                   getTitle                        Sub GetTitle (control As IRibbonControl, ByRef title)
toggleButton                    getPressed                      Sub GetPressed(control As IRibbonControl, ByRef returnValue)
toggleButton                    onAction - repurposed           Sub OnAction(control As IRibbonControl, pressed As Boolean, byRef cancelDefault)
toggleButton                    onAction                        Sub OnAction(control As IRibbonControl, pressed As Boolean)

 

参考资料:

IRibbonUI.InvalidateControl 方法 (Office) | Microsoft Learn

posted @ 2022-09-25 21:55  zionlew  阅读(1263)  评论(0编辑  收藏  举报