MS-Excel / General Formatting

Working with Ribbon Commands at Runtime

The controls you've seen so far are all ideally suited to running macros: You click a button or select a menu item, and the associated callback macro executes. That may be all you're really looking for as far as customizing the Ribbon goes. If so, you can cheerfully skip the rest of this tutorial. However, if you also want to set up the Ribbon to produce certain "states" that your macros can use, then you need to delve further into the RibbonX control toolkit.

Set of conditions that your macros can examine and to which they react accordingly. In practice, this means handling the following three tasks in your code:

  • Initializing controls-This means using code to set up your controls when your VBA application first loads. This might mean setting the state of a check box or toggle button, enabling or disabling a button, or populating a gallery element.
  • Resetting controls-This means re-initializing your controls.
  • Getting control values-This means using code to return the current state of some other control. With a check box control, for example, your macro can do one thing if the check box is activated, and it can do something else if it's deactivated.
  • Changing control values-This means using code to modify the current state of a control. For example, your code might change the state of a toggle button or change the selected item in a drop-down list.

The next three sections take you through each task in more detail.

[Previous] [Contents] [Next]