WD2000: How to Generate a List of Command Bar Names, Captions, and ID Numbers (243988)



The information in this article applies to:

  • Microsoft Word 2000

This article was previously published under Q243988

SUMMARY

In Microsoft Word, each element of the CommandBars collection uses a unique number for its ID property. This number determines the built-in action for each control in the CommandBars collection.

NOTE: The value of the ID property for Custom controls is 1.

The CommandBars collection consists of CommandBar objects. The following items are represented by CommandBar objects:
  • Menu bars, toolbars, and shortcut menus
  • Menus on menu bars and on toolbars
  • Submenus on menus, on submenus, and on shortcut menus

MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
For more information about how to use the sample code in this article, click the article number below to view the article in the Microsoft Knowledge Base:

212536 OFF2000: How to Run Sample Code from Knowledge Base Articles

The following macro example lists, in a new Word document, each of the controls in the CommandBars collection and its corresponding ID number. The controls and their ID numbers are arranged according to the CommandBar to which the control belongs, as in the following:

CommandBar Name: Standard | Caption: New &Blank Document | Face Id : 3813
CommandBar Name: Standard | Caption: &Open... | Face Id : 23
CommandBar Name: Standard | Caption: &Save | Face Id : 3
CommandBar Name: Standard | Caption: &Mail Recipient | Face Id : 3738
CommandBar Name: Standard | Caption: &Print | Face Id : 2521

Sub FindFaceIDsWordDocument()

'This code prints the information to a new Word document.

Dim c As CommandBar, ctl As CommandBarControl

Application.Documents.Add

For Each c In Application.CommandBars
   For Each ctl In c.Controls
      If ctl.Type = msoControlButton Then
         Selection.TypeText "CommandBar Name: " & c.Name & _
            " | Caption: " & ctl.Caption & " | Face Id : " & ctl.FaceId
         Selection.TypeParagraph
      End If
   Next
Next

End Sub
				

REFERENCES

For additional information about resources for creating custom solutions by using Visual Basic for Applications and Microsoft Word 2000, click the article number below to view the article in the Microsoft Knowledge Base:

212623 WD2000: Macro Programming Resources

226118 OFF2000: Programming Resources for Visual Basic for Applications


Modification Type:MinorLast Reviewed:10/11/2006
Keywords:kbhowto kbmacroexample KB243988