Microsoft Office Tutorials and References
In Depth Information
Example 12-3. Code to Generate a List of Control 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
Id
The ID of the control
Tag
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.
Example 12-3. Code to Generate a List of Control IDs
Public Sub ListControlIDs()
Dim fr As Integer
Dim cbar As Office.CommandBar
Dim ctl As CommandBarControl
Dim i As Integer
 
Search JabSto ::




Custom Search