How can I get list of commands and relevant the commands ID(identification numbers)?

A

avkokin

Hello. There is some code:
Set oBtn = oPopUp.Controls.Add(msoControlButton, 1589)
Question: how can I get list of commands and relevant the commands ID
(identification numbers)?
Thank you.
 
J

Jean-Guy Marcil

avkokin said:
Hello. There is some code:
Set oBtn = oPopUp.Controls.Add(msoControlButton, 1589)
Question: how can I get list of commands and relevant the commands ID
(identification numbers)?
Thank you.

Run this code (Depending on your system it can take a few seconds or a few
minutes...). Make sure you have nothing but a blank document active.

Option Explicit

Sub GetAllControlID()

Dim toolbarAll As CommandBar
Dim ctrAll As CommandBarControl
Dim colID As Collection
Dim colCap As Collection
Dim i As Long
Dim rgeDoc As Range

Const strLabel As String = "Toolbar Name:"
Set rgeDoc = ActiveDocument.Range
rgeDoc.Collapse wdCollapseStart

Set colID = New Collection
Set colCap = New Collection

For Each toolbarAll In Application.CommandBars
colID.Add strLabel
colCap.Add toolbarAll.Name
For Each ctrAll In toolbarAll.Controls
colID.Add ctrAll.ID
colCap.Add ctrAll.Caption
Next
Next

For i = 1 To colID.Count
With rgeDoc
.InsertAfter colID(i) & vbTab
.InsertAfter colCap(i) & vbCrLf
If colID(i) = strLabel Then
With .Paragraphs(.Paragraphs.Count).Range
With .Font
.Bold = True
.Size = 14
End With
With .ParagraphFormat
.SpaceBefore = 12
.SpaceAfter = 3
.KeepWithNext = True
End With
End With
End If
End With
Next

rgeDoc.ConvertToTable vbTab

End Sub
 
A

avkokin

Run this code (Depending on your system it can take a few seconds or a few
minutes...). Make sure you have nothing but a blank document active.

Option Explicit

Sub GetAllControlID()

Dim toolbarAll As CommandBar
Dim ctrAll As CommandBarControl
Dim colID As Collection
Dim colCap As Collection
Dim i As Long
Dim rgeDoc As Range

Const strLabel As String = "Toolbar Name:"
Set rgeDoc = ActiveDocument.Range
rgeDoc.Collapse wdCollapseStart

Set colID = New Collection
Set colCap = New Collection

For Each toolbarAll In Application.CommandBars
š š colID.Add strLabel
š š colCap.Add toolbarAll.Name
š š For Each ctrAll In toolbarAll.Controls
š š š š colID.Add ctrAll.ID
š š š š colCap.Add ctrAll.Caption
š š Next
Next

For i = 1 To colID.Count
š š With rgeDoc
š š š š .InsertAfter colID(i) & vbTab
š š š š .InsertAfter colCap(i) & vbCrLf
š š š š If colID(i) = strLabel Then
š š š š š š With .Paragraphs(.Paragraphs.Count).Range
š š š š š š š š With .Font
š š š š š š š š š š .Bold = True
š š š š š š š š š š .Size = 14
š š š š š š š š End With
š š š š š š š š With .ParagraphFormat
š š š š š š š š š š .SpaceBefore = 12
š š š š š š š š š š .SpaceAfter = 3
š š š š š š š š š š .KeepWithNext = True
š š š š š š š š End With
š š š š š š End With
š š š š End If
š š End With
Next

rgeDoc.ConvertToTable vbTab

End Sub

Thanks, Jean-Guy Marcil!
 
A

avkokin

Thanks, Jean-Guy Marcil!

Hello again.
How can I get list of commands (and ID) from the ribbon and commands
from groups (Word 2007)? These commands miss into the list of commands
for Toolbars, e.g. Special Paste (or PasteSpecialDialog). Thank you
very much!
 
J

Jean-Guy Marcil

avkokin said:
Hello again.
How can I get list of commands (and ID) from the ribbon and commands
from groups (Word 2007)? These commands miss into the list of commands
for Toolbars, e.g. Special Paste (or PasteSpecialDialog). Thank you
very much!

I do not have 2007 installed on my machine so I cannot test any code for that.

You should start a new thread with a specific question about 2007 so that
the 2007 experts will see it, in case they miss this thread...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top