1

I have two buttons which I've added to the Quick Access Toolbar (QAT) in MS Word, both of which are linked to macros written in a module. I want the second button to be greyed out (or locked) until the first one has successfully run, at which point I will unlock in the code.

How do I access the button objects with vba? I'm looking for something along the lines of ActiveDocument.QATButton1.Locked = True. With a standard Active X button you can right click and view properties to get the button name but I can't seem to do this with these (they were created via Options>QAT>Macros>Add)

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
Braide
  • 155
  • 3
  • 3
  • 13
  • 2
    You'll need to add CustomUI xml to the template/document, add the buttons to the ribbon and create callbacks for them. The QAT is specific to the user, can't be made available to other users, and can't be interacted with in VBA. – Timothy Rylatt Oct 14 '22 at 13:57
  • Enabling and disabling buttons goes beyond what the program interface can do. To make that happen, you need to get into RibbonUI and editing the template XML. Here's an introductory page: https://gregmaxey.com/word_tip_pages/customize_ribbon_main.html You're looking for information about _getEnabled callbacks_ to disable and enable buttons. – John Korchok Oct 14 '22 at 15:51

1 Answers1

0

If you want to disable or enable your Fluent UI controls (QAT) dynamically you need to use ribbon callbacks with IRibbonUI.Invalidate or IRibbonUI.InvalidateControl methods. For each of the callbacks that the custom UI implements, the responses are cached.

For example, if an add-in writer implements the getEnabled callback procedure for a button, the function is called once, the state loads, and then if the state needs to be updated, the cached state is used instead of recalling the procedure. This process remains in place until the add-in signals that the cached values are invalid by using the Invalidate method, at which time, the callback procedure is again called and the return response is cached. The add-in can then force an immediate update of the UI by calling the Refresh method.

You may find the Ribbon UI (aka Fluent UI) described in depth in the following series of articles:

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45