问题描述
我正在尝试学习新知识.我已经基于Siddharth Rout的教程创建了一个自定义标签.XML部分就是这样
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
但是当我打开工作簿时,遇到错误无法运行宏RibbonOnLoad
.我正在使用Office 365 32位和Windows 10 64位.
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.
推荐答案
首先,正如已经提到的freeflow一样,回调应为 RibbonOnLoad
.其次,您应该使用ActivateTab方法,因为它是一个自定义选项卡.第三,您应该指定控件ID,而不是选项卡名称.尝试以下代码,这些代码需要放在常规模块中...
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
这篇关于在功能区中添加自定义选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!