Custom Ribbon fails on Invalidate

CurtisD

New Member
Joined
Oct 4, 2019
Messages
15
Hello,

I am learning how to create and work with a custom ribbon in Excel 2019, but clearly have much to learn. I am running Windows 10.

I created the XML and callback functions from examples I've seen on various Excel websites. I am not trying to create an add-in.
When I open the Excel workbook the following error appears:

Error 91 - Object variable or with block variable not set

The line that is highlighted is:

testRibbon.Invalidate

I can't see the code in the Invalidate method since that is a built in method.

I'm hoping someone can help with this problem. I have a few thoughts:

- Perhaps the schema 2009/07 should be replaced with another one?
- Perhaps I need to set a reference to a library to get this to work?

Thank you.

Below is the XML and the callback functions.

XML

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
<ribbon>
<tabs>
<tab id="Tab1" label="Jobs on Hiatus">
<group id="Group1" label="Jobs on Hiatus">
<dropDown
id="DropDown"
label="Select Job To&#xA;Return from Hiatus"
getItemCount="DropDown_getItemCount"
getItemID="DropDown_getItemID"
getItemLabel="DropDown_getItemLabel"
getSelectedItemID="DropDown_getSelectedItemID"
onAction="DropDown_onAction" />
</group>
</tab>
/tabs>
</ribbon>
</customUI>


Callback functions

Option Explicit

'testRibbon is a variable which contains the Ribbon
Public testRibbon As IRibbonUI

'Callback for customUI.onLoad
Public Sub testRibbon_onLoad(ribbon As IRibbonUI)
Set testRibbon = ribbon
End Sub

'Callback for DropDown getItemCount
Public Sub DropDown_getItemCount(control As IRibbonControl, ByRef returnedVal)
returnedVal = numberOfRowsOnSheet("Hiatus")
End Sub

'Callback for DropDown getItemLabel
Public Sub DropDown_getItemLabel(control As IRibbonControl, index As Integer, ByRef returnedVal)
returnedVal = Worksheets("Hiatus").Cells(index + 1, 18)
End Sub

'Callback for DropDown onAction
Public Sub DropDown_onAction(control As IRibbonControl, id As String, index As Integer)
Call doHiatusJobReturn
End Sub

Public Sub DropDown_getItemID(control As IRibbonControl, index As Integer, ByRef id)
'This Callback will set the id for each item created.

id = Format(index + 1)

End Sub

Public Sub DropDown_getSelectedItemID(control As IRibbonControl, ByRef id)
'This Callback will change the drop-down to be set to a specific the id.

id = "1"

End Sub

Public Sub updateRibbon()
'This is a standard procedure, not a Callback. It is triggered by the button.
'It invalidates the Ribbon, which causes it to re-load.

On Error Resume Next
testRibbon.Invalidate
On Error GoTo 0

End Sub
 
Last edited:

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Welcome to the MrExcel Message Board!

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Custom Ribbon Fails When Invalidate Method Called
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
Your XML isn't calling the onLoad at all. You need:

HTML:
<customUI onLoad="testRibbon_onLoad" xmlns="http://schemas.microsoft.com/office/2009/07/customui">
 
Upvote 0
Your XML isn't calling the onLoad at all. You need:

HTML:
<customUI onLoad="testRibbon_onLoad" xmlns="http://schemas.microsoft.com/office/2009/07/customui">
Thank you, Rory. That worked. Your help is appreciated!
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,207
Members
452,618
Latest member
Tam84

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