Home > front end >  AddIn IRibbonUI callbacks and .Invalidate fails after it installs any other AddIn with its own IRibb
AddIn IRibbonUI callbacks and .Invalidate fails after it installs any other AddIn with its own IRibb

Time:01-31

Description: This is Excel 2013 VBA case. 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". 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). I use a lot of callback functions for purpose of full customization of all elements from 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. 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. Despite a lot of efforts, I cannot figure it out.

Relevant part of CustomUI XML:

<customUI onl oad="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 onl oad(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:

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
  • I tried to move onl oad sub to ThisWorkbook module. I understand, that moving callbacks to ThisWorkbook is wrong way. I also tried ThisWorkbook and ThisAddin prefixes to IRibbonControl argument, but thats also wrong way. So far with my tries to somehow differentiate eventual IRibbonControl duplicities (my idea only).
  • I tried to rename IRibbonUI objects in other AddIns without any progress.
  • 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. https://excelguru.ca/?s=ribbon part
  • Any ideas and especially simple solutions of this problem are very welcomed, thank you very much

CodePudding user response:

Solved.

First line of XML file of all my AddIns looked like this and that was a source of all problems described before.

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

Same name for onl oad procedure in different AddIns resulted in described behaviour including earlier mentioned error when 2 or more AddIns with this same name was installed. Renaming onl oad procedures to different names solved everything instantly.

Source which helped me: https://excelguru.ca/debugging-ribbonx-invalidateinvalidatecontrol-failures…/

  • Related