简体   繁体   English

AddIn IRibbonUI 回调 and.Invalidate 在安装任何其他具有自己的 IRibbonUI 的 AddIn 后失败

[英]AddIn IRibbonUI callbacks and .Invalidate fails after it installs any other AddIn with its own IRibbonUI

Description: This is Excel 2013 VBA case.描述:这是 Excel 2013 VBA 案例。 I created AddIn which should be able to install and uninstall another AddIns from AddIn list stored in global variable "listOfAddIns" which is Array of Arrays of Variant Type called "valueArray".我创建了 AddIn,它应该能够从存储在全局变量“listOfAddIns”中的 AddIn 列表中安装和卸载另一个 AddIns,该变量类型为 Arrays 的数组,称为“valueArray”。 There are "group control" buttons (for purpose of install or uninstall all available addins) and "individual control" toogle buttons (for install or uninstall specific AddIn).有“组控制”按钮(用于安装或卸载所有可用插件)和“单独控制”toogle 按钮(用于安装或卸载特定插件)。 I use a lot of callback functions for purpose of full customization of all elements from VBA.我使用了很多回调函数来完全自定义 VBA 中的所有元素。

Problem: Everything works perfectly for installing/uninstalling AddIns without their own Ribbon Tabs.问题:在没有自己的功能区选项卡的情况下,一切都可以完美地安装/卸载插件。 Once installed AddIn has its own Ribbon Tab, I am no longer able to use ribbon object.Invalidate method and call callbacks.安装插件后,它有自己的功能区选项卡,我将无法再使用功能区 object.Invalidate 方法和调用回调。 I get this poorly descriped Error Message:我收到这个描述不清的错误消息:

Run-Time error'-2147467259(80004005)': Method 'Invalidate' of object 'IRibbonUI' failed

My Idea: Due to described symptomns, I suspect, that there are some duplicity problems of IRibbonControl from different AddIns.我的想法:由于所描述的症状,我怀疑不同加载项的 IRibbonControl 存在一些口是心非的问题。 Despite a lot of efforts, I cannot figure it out.尽管付出了很多努力,但我无法弄清楚。

Relevant part of CustomUI XML: CustomUI XML的相关部分:

<customUI onLoad="OnLoad" xmlns="http://schemas.microsoft.com/office/2006/01/customui">
 
    <ribbon startFromScratch="false">
        <tabs>
            <tab id = "INST1ID" label="Installer">
        <group id="GroupControls" label="Group controls">                   
            <button id="B1ID" label="Install All" size="large" onAction="InstallAll" imageMso="AcceptInvitation" />  
            <button id="B2ID" label="Uninstall ALL" size="large" onAction="UninstallAll" imageMso="MasterViewClose" />               
        </group>
        <group id="IndividualControls" label="Individual controls">
            <toggleButton id="TB1ID" imageMso="HappyFace" label="AddIn1" onAction="TBsControl" size="large" tag="1" getEnabled="TBsGetEnabled" getPressed="TBsGetPressed" getVisible="TBsGetVisible" />
            <toggleButton id="TB2ID" imageMso="HappyFace" label="AddIn2" onAction="TBsControl" size="large" tag="2" getEnabled="TBsGetEnabled" getPressed="TBsGetPressed" getVisible="TBsGetVisible" />
            <toggleButton id="TB3ID" imageMso="HappyFace" label="AddIn3" onAction="TBsControl" size="large" tag="3" getEnabled="TBsGetEnabled" getPressed="TBsGetPressed" getVisible="TBsGetVisible" />
        </group>
            </tab>
        </tabs>
    </ribbon>
 
</customUI>

OnLoad Sub:加载子:

Public Sub OnLoad(ribbon As IRibbonUI)

Set ribbonObject = ribbon

End Sub

Main procedure for "Group control" example: “群控”示例的主要流程:

Public Sub InstallAll(control As IRibbonControl)

Call ResetSomePublicVariables
Call CreateEntryValuesAndFillToListOfAddIns
Call CheckAvailabilityAndInstallationOfAddInsAndFillToListOfAddIns
Call UpdateListOfAddInsToInstallAllAvailableAddIns
Call InstallOrUninstallAddInsDueToListOfAddIns

ribbonObject.Invalidate

End Sub

Main procedure for "Individual control" and expanded 4th Sub: “个人控制”的主要程序和扩展的第 4 个子程序:

Public Sub TBsControl(control As IRibbonControl, pressed As Boolean)

Call ResetSomePublicVariables
Call CreateEntryValuesAndFillToListOfAddIns
Call CheckAvailabilityAndInstallationOfAddInsAndFillToListOfAddIns
Call UpdateListOfAddInsDueToToogleButtonRequest(control.tag, pressed)
Call InstallOrUninstallAddInsDueToListOfAddIns

ribbonObject.Invalidate

End Sub

Public Sub UpdateListOfAddInsDueToToogleButtonRequest(tag As Long, pressed As Boolean)

Dim valueArray() As Variant

valueArray = listOfAddIns(tag)

If pressed = True Then
    valueArray(VAColumnIndex_Installed) = 1
Else
    valueArray(VAColumnIndex_Installed) = 0
End If

listOfAddIns(tag) = valueArray

End Sub

Callback example:回调示例:

Public Sub TBsGetVisible(control As IRibbonControl, ByRef returnedVal)

For Each Item In listOfAddIns
    If control.tag = Item(VAColumnIndex_Number) Then
        returnedVal = True
        Exit For
    Else
        returnedVal = False
    End If
Next Item

End Sub
  • I didnt used Custom UI Editor or similar software and I guess that it will not be helpful in this phase我没有使用 Custom UI Editor 或类似的软件,我想在这个阶段它不会有帮助
  • I tried to move onLoad sub to ThisWorkbook module.我试图将 onLoad sub 移动到 ThisWorkbook 模块。 I understand, that moving callbacks to ThisWorkbook is wrong way.我知道,将回调移动到 ThisWorkbook 是错误的方法。 I also tried ThisWorkbook and ThisAddin prefixes to IRibbonControl argument, but thats also wrong way.我还尝试了 ThisWorkbook 和 ThisAddin 前缀到 IRibbonControl 参数,但这也是错误的方式。 So far with my tries to somehow differentiate eventual IRibbonControl duplicities (my idea only).到目前为止,我试图以某种方式区分最终的 IRibbonControl 重复(仅我的想法)。
  • I tried to rename IRibbonUI objects in other AddIns without any progress.我尝试在其他插件中重命名 IRibbonUI 对象,但没有任何进展。
  • I read a lot of sources and saw a lot of examples and different approaches on Microsoft, StackOverFlow on link below but it didnt helped me with this.我阅读了很多资料,看到了很多关于微软的例子和不同的方法,下面链接中的 StackOverFlow 但它并没有帮助我解决这个问题。 https://excelguru.ca/?s=ribbon+part https://excelguru.ca/?s=ribbon+part
  • Any ideas and especially simple solutions of this problem are very welcomed, thank you very much非常欢迎任何想法,特别是这个问题的简单解决方案,非常感谢

Solved.解决了。

First line of XML file of all my AddIns looked like this and that was a source of all problems described before.我所有插件的 XML 文件的第一行看起来像这样,这是前面描述的所有问题的根源。

<customUI onLoad="OnLoad" xmlns="http://schemas.microsoft.com/office/2006/01/customui">

Same name for onLoad procedure in different AddIns resulted in described behaviour including earlier mentioned error when 2 or more AddIns with this same name was installed.当安装了 2 个或多个具有相同名称的插件时,不同插件中 onLoad 过程的相同名称会导致描述的行为,包括前面提到的错误。 Renaming onLoad procedures to different names solved everything instantly.将 onLoad 过程重命名为不同的名称立即解决了所有问题。

Source which helped me: https://excelguru.ca/debugging-ribbonx-invalidateinvalidatecontrol-failures%E2%80%A6/对我有帮助的来源: https://excelguru.ca/debugging-ribbonx-invalidateinvalidatecontrol-failures%E2%80%A6/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM