1
votes

I am trying to learn something new. I have created a custom tab based on Siddharth Rout' tutorial. The XML part is like that

<customUI onLoad="RibbonOnLoad" xmlns="http://schemas.microsoft.com/office/2009/07/customui">
<ribbon startFromScratch="false">
<tabs>
<tab id="MyCustomTab" label="MyTab" insertAfterMso="TabView">
<group id="customGroup1" label="First Tab">
<button id="customButton1" label="JG Button 1" imageMso="HappyFace" size="large" onAction="Callback1" />
<button id="customButton2" label="JG Button 2" imageMso="PictureBrightnessGallery" size="large" onAction="Callback2" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>

Then in workbook module I put this code so as to activate the tab when the workbook is open

Private myRibbon As IRibbonUI

Sub OnLoad(ribbon As IRibbonUI)
Set myRibbon = ribbon
myRibbon.ActivateTabMso ("MyTab")
End Sub

But when I opened the workbook, I encountered an error Can't run the macro RibbonOnLoad. I am using Office 365 32 Bit and Windows 10 64 Bit.

1
To start, the OnLoad and OnAction items of the CustomUI specify the names of the VBA Methods that will be called. Thus your 'Sub OnLoad(....' method really needs to be 'Sub RibbonOnLoad(...) - freeflow
I tried RibbonOnLoad and saved closed wb then I got the same error. I tried to change myRibbon.ActivateTab ("MyTab") and removed the so part, saved an closed then I got the same error. - YasserKhalil
Are you using the CustomUI editor? github.com/OfficeDev/office-custom-ui-editor - freeflow
Sorry was watching a TV Series. This is the reason why I recommend creating a question rather than following up in comments. This way whoever is online and can answer, will answer your question. Glad it is resolved! :) - Siddharth Rout
@SiddharthRout Thank you very much. I really like and enjoy your awesome posts. - YasserKhalil

1 Answers

2
votes

First, as freeflow has already mentioned, the callback should be RibbonOnLoad. Secondly, you should be using the ActivateTab method, since it's a custom tab. And thirdly, you should be specifying the control ID, not the tab name. Try the following code, which needs to be placed in a regular module...

Private myRibbon As IRibbonUI

'Callback for customUI.onLoad
Sub RibbonOnLoad(ribbon As IRibbonUI)

    Set myRibbon = ribbon
    myRibbon.ActivateTab "MyCustomTab"

End Sub