Apply IRibbonUI.ActivateTab in Excel 2019

2020-04-10 03:51发布

I have existing VBA code (mine) working in Excel 2010 that activates a custom ribbon tab: IRibbonUIObjectName.ActivateTab "tabID"

The code exists as a standard operation in a sub that handles changes of active window (to activate the tab when relevant to do so).

This same code won't run in Excel 2019. At run-time, throws an exception

'invalid call or argument'

The code passes syntax checks and I've rebuilt the line by letting VBA prompt me.

i.e. type: 'IRibbonUIObjectName.' and let the editor supply ActivateTab (confirming object validity).

I have read current office dev documentation, and syntax hasn't changed.

The core questions:

1) Has anything changed since 2010?

2) How can this method be applied in Excel 2019? How to call the sub that executes the method? What is the exact syntax?


Additional information:

All other functionality of the tab and its controls function as they do in 2010 systems.

I am checking the ribbon object prior to execution per:

If Not mobQSRibbon Is Nothing Then mobQSRibbon.ActivateTab "plTAB_QuoteSystem" 

Name space:

customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="ModuleName.SubName" >

Additional information 2:

Further testing reveals the issue is not simply a syntactical one.

The method works sometimes. Specifically:

1) Executing the method after opening a workbook causes the exception - i.e. By executing ActivateTab while processing the WorkbookActivate event triggered as part opening of a workbook.

2) Executing the method while processing a WorkbookActivate event triggered by merely switching to an already open workbook, does not cause the exception.

3) Likewise, executing the method while processing a SheetActivate event by merely switching sheets does not cause the exception.

So the issue seems to do with something having changed in how Excel deals with the the ribbon, post workbook open.

标签: excel vba
0条回答
登录 后发表回答