Builtin Command BarControl IDs

As we will see in Example 12-3, it is possible to place built-in command-bar controls on toolbars (or menus). This is done by setting the Id parameter of the Add method of the CommandBarControls collection to the ID of the built-in command-bar control.

We must now address the issue of how to determine the IDs for the built-in controls. One approach to finding the ID of a particular control is to use the FindControl method to get a reference to the control. Once this is done, we can examine the control's ID property. The syntax for FindControl is:

expression.FindControl(Type, Id, Tag, Visible, Recursive)

where expression is either a CommandBar or CommandBars object. The other parameters are optional. The method returns the first CommandBarControl object that fits the criteria specified by the parameters, or Nothing if the search is unsuccessful. Briefly, the parameters are:

Type

One of the MsoControlType constants in the enum given earlier in this chapter

The ID of the control

The tag value of the control

Visible

Set to True to include only visible command-bar controls in the search

Recursive

True to include the command bar and all of its popup subtoolbars in the search

While the FindControl method can be quite useful, the problem in this situation is that the method requires another way to identify the control, such as through its Tag property. Thus, the FindControl method is most useful in finding a custom control that we have created and assigned a Tag value.

An alternative approach to getting built-in control IDs is to create a one-time list for future reference. The code in Example 12-3 will create a text file and fill it with a list of all built-in control names and IDs. (Note that it requires that a directory named \temp exist on your D: drive; feel free to change the drive and path to one suitable for your system.) The code creates a temporary toolbar, adds a built-in control for each possible control ID using a simple For loop, and then examines each of these controls. This is a rather ad hoc approach, but seems to be the only approach available.

0 0

Post a comment