How to call Ribbon button click handler from VBA

Mar 11, 2015 at 4:13 PM
Edited Mar 11, 2015 at 4:14 PM
In VBA, I can call context menu item like this

Set cmd = Application.CommandBars("Cell").Controls("My context menu item")
Just can't figure out how to do the same for my own ribbon button?

I googled and found this
but that is used add-in express

Mar 11, 2015 at 5:07 PM
The ribbon does not support invoking the onAction like this, so you'd need to call your handler code directly, yourself.
One way would be to keep a static reference to your ribbon handler object (which you set in the constructor). Even then you would not have an IRibbonControl to pass into the handler. Better would be to refactor your code to completely separate the ribbon handling and the macro work you want to do.

A different approach would be to use the Windows UI Automation support. It's quite a steep learning curve to get into that, though.