Consulting

Results 1 to 10 of 10

Thread: How can I get list of commands (and its ID) from the ribbon and groups (Word 2007)?

  1. #1
    VBAX Regular
    Joined
    Aug 2007
    Posts
    66
    Location

    How can I get list of commands (and its ID) from the ribbon and groups (Word 2007)?

    How can I get list of commands (and its ID) from the ribbon and groups (in the Word 2007)? These commands miss into the list of commands
    for Toolbars (if use one macro for building table of commands), e.g. Paste Special (or like PasteSpecialDialog).
    Thank you very much!

  2. #2
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    I'm not sure i fully understand what you are asking. Ribbon commands do not, as far as I know, relate to toolbar commands in any useful way.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  3. #3
    VBAX Regular
    Joined
    Aug 2007
    Posts
    66
    Location
    Sorry.
    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) from Word 2007?
    If use macro (show below), than will building the table with list of the commands for tollbars. But it not have some commands, e.g. "Special Paste" that is on the "Home" tab (in the "Clipboard" group).
    I need it. Thank you.
    That code (many thanks Jean-Guy Marcil):
    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
    Further to my post:
    I wrote automacro in the Word 2003 that add the command "Paste Special". Then I see code and recognized it ID - 755. But how can I get all these ID. That is the question! Thank you.
    Last edited by akokin; 03-07-2008 at 03:17 AM.

  4. #4
    Is this any use to you?

    2007 Office System Document: Lists of Control IDs
    http://www.microsoft.com/downloads/d...displaylang=en

  5. #5
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    Now I understand. This has nothing to do with Word 2007, and, unfortunately, it is not entirely straightforward either.

    When you iterate over the CommandBars collection you do not get all the CommandBars. In particular, you do not get some (maybe all) of those that PopUp from Controls of types msoControlPopup and msoControlButtonPopup.

    As there may be a hierarchy of menus, of theoretically any depth, you need to rework your macro into a recursive process, not least because neither Name nor NameLocal is guaranteed unique for either a CommandBar or a Control.

    From a quick look that will require quite a bit of rework. If you get stuck, do come back.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  6. #6
    VBAX Regular
    Joined
    Aug 2007
    Posts
    66
    Location
    Quote Originally Posted by Nelviticus
    Is this any use to you?

    2007 Office System Document: Lists of Control IDs
    http://www.microsoft.com/downloads/d...displaylang=en
    Yes, it is. But it on English, and I need to Russian. Thus and so I need to the macro for building the list of controls IDs with russian name of commands (local language).
    Thank you very much.

  7. #7
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    Quote Originally Posted by akokin
    Yes, it is. But it on English, and I need to Russian. Thus and so I need to the macro for building the list of controls IDs with russian name of commands (local language).
    Thank you very much.
    Now I'm officially confused. Do you want the IDs of controls on Word 2003's toolbars or do you want the (English alpha) comand names for the buttons on Word 2007's Ribbon. Or something else? Where do you want to use the values you finally get?
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  8. #8
    VBAX Regular
    Joined
    Aug 2007
    Posts
    66
    Location
    Tony, sorry for my bad English. I want to get the macro that will build list of the commands and them IDs for the buttons on Word 2007's Ribbon (and for other commands that miss on the Ribbon). Next I want to use these values (IDs) into the macro, that add into the shortcut Menu any commands or buttons, e.g. "Paste Special". That is sample:
    Sub newItemToContextMenu()
    Dim cb As CommandBar
    Dim cbb As CommandBarButton
    Dim cbc As CommandBarControl
    CustomizationContext = NormalTemplate  
    On Error GoTo Ex
    Set cb = CommandBars("text")  
    Set cbb = cb.FindControl(ID:=755) 
    If Not cbb Is Nothing Then Exit Sub 
    Set cbb = cb.Controls.Add(msoControlButton, 755, 1)  
    Set cbb = Nothing 
    Ex:
    End Sub
    Is there any way get that macro?

  9. #9
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    Your English is better than my Russian

    What your code does is look at the ToolBars - which do still exist in Word 2007 - it does not look at the Ribbon. Yes, many of the same buttons exist on both but there may be some that don't and you cannot look at the Ribbon in VBA.

    I have changed your code to look at all the toolbars. Is this helpful?


    [VBA]
    Option Explicit

    Const strLabel As String = "Toolbar Name:"

    Dim colID As Collection
    Dim colCap As Collection

    Sub GetAllControlIDOriginal()

    Dim toolbarAll As CommandBar
    Dim i As Long
    Dim rgeDoc As Range

    With Documents.Add
    .PageSetup.Orientation = wdOrientLandscape
    Set rgeDoc = .Range
    rgeDoc.Collapse wdCollapseStart
    End With

    Set colID = New Collection
    Set colCap = New Collection

    For Each toolbarAll In Application.CommandBars
    CheckToolBar toolbarAll
    Next

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

    rgeDoc.ConvertToTable vbTab
    End Sub

    Sub CheckToolBar(ToolBar As CommandBar, Optional Level As Long)

    Dim ctrAll As CommandBarControl

    colID.Add Space(4 * (Level)) & strLabel
    colCap.Add Space(4 * (Level)) & ToolBar.Name
    For Each ctrAll In ToolBar.Controls
    If ctrAll.Type = msoControlPopup _
    Or ctrAll.Type = msoControlButtonPopup Then
    CheckToolBar ctrAll.CommandBar, Level + 1
    Else
    colID.Add Space(4 * (Level + 1)) & ctrAll.ID
    colCap.Add Space(4 * (Level + 1)) & ctrAll.Caption
    End If
    Next

    End Sub

    [/VBA]
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  10. #10
    VBAX Regular
    Joined
    Aug 2007
    Posts
    66
    Location
    Tony, it's good! Yes, thank you very much! It's very helpful! It that I need.
    Sincerely, Anton.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •