Example 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

Const maxid = 4000 fr = FreeFile

Open "d:\temp\ids.txt" For Output As #fr ' Create temporary toolbar

Set cbar = Application.CommandBars.Add("temporary", msoBarTop, False, True)

On Error Resume Next ' skip if cannot add cbar.Controls.Add Id:=i Next i

On Error GoTo 0

For Each ctl In cbar.Controls

Print #fr, ctl.Caption & " " & ctl.Id Next cbar.Delete Close #fr

Example 12-4 shows a small portion of the resulting file when the code is run on my system. Appendix C, contains a complete list.

0 0

Post a comment