Problem with Ribbon control.invalidate

indyman

New Member
Joined
Apr 14, 2021
Messages
47
Office Version
  1. 2019
Platform
  1. Windows
I have an XLSM with a customUI ribbon tab to be distributed to users. I will issue code updates via a New.XLSM. All code being executed is no New.XLSM. I have an Update button on the tab, that the user will invoke, which calls one sub –“Run Update”.

VBA Code:
Sub Run_Update()
    'Asks user to open the Existing XLSM
    'Performs several validations
    'Saves a backup of Existing.XLSM, although it does not alter that file at all
    'A modal userform is displayed during the update , “Processing…”
    'Uprotect WB and a few sheets
    'Copies certain data sheets from Existing XLSM to New.SLXM
    'Logs process to logfile.
    'Displays userform now saying …process completed…
    'Closes Exiting.XLSM and leaves New.xlsm open
    'Hides some sheets
    'Protects New.XLSM and the sheets
End Sub

I can verify that the sub completes.

The problem is after it completes. After the “completed” message is displayed, it immediately raises the following error:
“Method “InvalidateControl” of IRibbonUI failed.”
It raises this error on all controls that have a getText callback – 2 editboxes and 1 label. If I click End, the file crashes and closed. The values of those controls are stored in a worksheet. I can change the editboxes all day long and run all the other ribbon controls as well without issue. The Update sub does not touch any ribbon controls, other than being called from the Update button. Here is the code for one editbox, and similar to the other textbox.
VBA Code:
'Callback for editYears getText
Sub GetYears(control As IRibbonControl, ByRef sNumberOfYears)
    sNumberOfYears = ThisWorkbook.Sheets("User Input").Range("C23")
    If myRibbon Is Nothing Then
        Set myRibbon = GetRibbon(sNumberOfYears)
        myRibbon.InvalidateControl "editYears"
    Else
        sNumberOfYears = ThisWorkbook.Sheets("User Input").Range("C23")
        myRibbon.InvalidateControl "editYears"    'it fails on the Else clause
    End If
End Sub

“User Input” is an xlVeryHidden sheet. MyRibbon is set in the ribbon load callback

VBA Code:
'Callback for customUI.onLoad
Sub onLoad(ribbon As IRibbonUI)
   Set myRibbon = ribbon
   'Store pointer to IRibbonUI
   ThisWorkbook.Sheets("User Input").Range("C27").Value = ObjPtr(myRibbon)
End Sub

I have looked all over for solutions, but not finding anything. Does anyone have any ideas why this is happening or can offer some troubleshooting ideas?
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
My problem is resolved, but I am not sure what fixed it. I just stripped as much code out of the middle of the update sub, but still allow it to run. It no longer ran into the Invalidate.control error. So I started adding sections back in until it failed. It failed where I had 2 consecutive VBA.DoEvents. (not sure why I left 2 in there.) It did not fail when I removed one of them. But that was apparently a red herring as it did subsequently fail again. I tried a few other things. And in the file compare, I moved 2 procedure calls to the end of the update sub - one that recalculates the data, and one that writes to the logfile.

I can't see any connection to the ribbon issue. But now I am wondering if this caused some correction in the recompile. I am grasping at straws on that one. But nonetheless, it seems to be working now.
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,435
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top