I have developed a Global Template in Microsoft Word, a .dotm that sits in the user's AppData\…\Word\STARTUP folder, so it gets loaded every time the user launches MS Word. The .dotm creates a custom tab in the Word ribbon menu, a toolbar containing numerous automation macro buttons.
I need to do certain checks each time they use the global template, such as making sure they have the latest version, etc. I am currently triggering these checks by way of the RibbonOnLoad event. Problem is the ribbon loads when the user first launches the Word application.
I would rather trigger these checks only when the user switches to my custom tab. Is there a Word VBA Event that fires when the user changes to a certain ribbon menu tab?
My research suggests there is no such event. But I want to make sure. If not, is there a workaround to create this same functionality, so I don't have to call the checks at the beginning of every single macro?
Thanks!
Sure, simply use a private Boolean variable. Set it to True after you run your checks. And add a guard clause to each method. This allows you to run your macros be invoking them also by Run Macro dialog or the command line.
When you really want to use an event, than add a getVisible or getEnabled event handler to your groups in ribbon XML and your code behind. They are called the first time a group is shown after the start or an invalidate call affecting the group.