我正在使用此代码,但是当excel尝试加载它时我收到错误,在excel 365上正常工作但在excel 2007上抛出错误:
<customUI onLoad="RibbonOnLoad"
xmlns="http://schemas.microsoft.com/office/2006/01/customui">
Public Rib As IRibbonUI
Sub RibbonOnLoad(ribbon As IRibbonUI)
Set Rib = ribbon
End Sub
Sub startHereConfigure()
Rib.ActivateTab "Configure"
End Sub
在这里称呼它:
Private Sub Workbook_Open()
startHereConfigure '<<<<-getting object doesn't support this property or method
end sub
您可以使用Application.SendKeys
发送可以激活功能区选项卡的Alt键组合,但如果代码在Excel 14.0或更高版本(2010+)中运行,那么我将保持ActivateTab
调用,这更加强大。
由于您收到错误438,我认为成员调用是后期绑定的(在运行时解析),否则代码甚至不会编译,更不用说运行了。
当代码在运行时被解析时,你可以使用条件逻辑来实现它,有条件的 - 验证Application.Version
,并相应地进行分支:
If Application.Version >= 14 Then
'Excel 2010+
Rib.ActivateTab "Configure"
''or explicitly late-bound:
'Dim ui As Object
'Set ui = Rib
'ui.ActivateTab
Else
Application.SendKeys "%C" ' assuming "Alt+C" activates the "Configure" tab; tweak accordingly.
End If