Id Property (CommandBarButton Object)

Object: CommandBarButton Object

Access: Read-Only

Returns the ID of the command associated with the commandbar button.

Usage

CommandBarButton.Id

Arguments

None.

Return Values

A long that represents the ID of command associated with the commandbar button.

Examples

' 
' This example walks through the menus of a PCB application and 
' write the menu name and its command ID out to a output file. 
' 
' Create an output file 
Set filesys = CreateObject("Scripting.FileSystemObject") 
file = "c:\temp\output.txt" 
Set filetxt = filesys.CreateTextFile(file, True) 
 
' Get the document menu bar object 
Dim docMenuBar 
Set docMenuBar = Gui.CommandBars("Document Menu Bar")  
 
' Walk through all menu in the menu bar 
' and write out its name and command id 
' to a file 
xTab = vbTab 
For i = 1 To docMenuBar.Controls.Count 
     Set menu = docMenuBar.Controls.Item(i) 
     filetxt.WriteLine "+" & menu.Caption 
     Call WriteMenuIDs(menu) 
     filetxt.WriteLine 
Next 
' Subroutine to write out menu item name  
' and its command ID 
Sub WriteMenuIDs(menu) 
     Set menuCtrls = menu.Controls 
     For j = 1 To menuCtrls.Count 
         cmdName = menuCtrls.Item(j).Caption 
         On Error Resume Next 
         id = menuCtrls.Item(j).Id 
         If Err Then 
             ' CommandBarPopup doesn't support Id property 
             Err.Clear 
             filetxt.WriteLine xTab & cmdName 
             saveTab = xTab 
             xTab = xTab & vbTab 
             Call WriteMenuIDs(menuCtrls.Item(j)) 
             xTab = saveTab 
         ElseIf id <> 0 Then 
             ' Don't write out separator whose command id is 0 
             filetxt.WriteLine xTab & cmdName & " : " & id 
         End If 
     Next 
End Sub 
MsgBox "fini"