Results 1 to 13 of 13

Thread: How do I Find control IDs in Visual Basic for Applications for office 2003?

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    6

    How do I Find control IDs in Visual Basic for Applications for office 2003?

    I'm working on deploying office 2003 and I need to restrict/hide several of the pull down menu options as well as tool bar buttons. I found I can do this in an office 2003 policy in gpedit however I need some control ID's according to:


    Finding control IDs in Visual Basic for Applications


    (snip)
    "...To disable any other command in an Office 2003 application, you set the Custom | Disable command bar buttons and menu items policy and add the control ID for the command you want to disable...

    Finding control IDs in Visual Basic for Applications

    You can look up control IDs for any item on a menu or toolbar in Office 2003 applications by using Microsoft Visual Basic® for Applications (VBA). You can either look up a single control ID or use a macro to find a series of control IDs. Then you enter the control ID into the Group Policy snap-in to disable that menu command and toolbar button."
    (/snip)


    Sooo.. I went and tracked down a copy of VBA 6.4, got a copy sent to me by mail and I installed it hoping it would be fairly straight forward (as I am not a programmer and have no experience in visual basic). I was hoping VBA was a program I could run.. then from there open the office exe files on my pc in an effort to locate those control ID's.. Well it doesn't work that way so I tried something else. I then ran word2003, hit alt+f11 (which opens VB) and used the script from the above web page:

    Sub EnumerateControls()
    Dim icbc As Integer
    Dim cbcs As CommandBarControls
    Set cbcs = Application.CommandBars("Menu Bar").Controls("File").Controls
    For icbc = 1 To cbcs.Count
    MsgBox cbcs(icbc).Caption & " = " & cbcs(icbc).ID
    Next icbc
    End Sub

    I pasted this into a new macro and clicked on run which didn't work..
    I'm pretty much running out of ideas and wondering if I'm in over my head or if this is possible for me to do.. thus I'm here for advice.

    Can anyone tell me what I would need to do with VBA so I can find office command ID's?

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: How do I Find control IDs in Visual Basic for Applications for office 2003?

    ok there is probably more.. but here is a quick macro: (for word.. but should work in excel (except the typtext part )
    VB Code:
    1. Private Sub PrintIDs()
    2.  
    3. Dim CBTN As CommandBarButton
    4. Dim CBR As CommandBar
    5. On Error Resume Next
    6.  
    7. For Each CBR In Application.CommandBars
    8.     For Each CBTN In CBR.Controls
    9.         Selection.TypeText CBR.Name & ": " & CBTN.ID & " - " & CBTN.Caption
    10.         Selection.TypeParagraph
    11.     Next
    12. Next
    13.  
    14. End Sub

    and here is part of list it dumped: (See comment below)
    Code:
    Standard: 2520 - New &Blank Document
    Standard: 23 - &Open...
    Standard: 3 - &Save
    Standard: 9004 - Permission (Unrestricted Access)
    Standard: 3738 - &Mail Recipient
    Standard: 2521 - &Print
    Standard: 109 - Print Pre&view
    Standard: 2566 - &Spelling and Grammar...
    Standard: 7343 - &Research...
    Standard: 21 - Cu&t
    Standard: 19 - &Copy
    Standard: 22 - &Paste
    Standard: 108 - &Format Painter
    Formatting: 5757 - &Styles and Formatting...
    Tables and Borders: 2059 - Dra&w Table
    Tables and Borders: 2060 - &Eraser
    Database: 3272 - &Data Form
    Database: 3124 - &Manage Fields
    Database: 213 - &Add Record
    Database: 214 - &Delete Record
    Database: 3157 - Sort &Ascending
    Database: 3158 - Sort Des&cending
    Database: 216 - &Database...
    Database: 215 - &Update Field
    Database: 183 - &Find in Field
    Database: 244 - &Main Document
    
    Drawing: 182 - &Select Objects
    Forms: 219 - &Edit Box
    Forms: 220 - C&heck Box
    Forms: 221 - &Combo Box
    Forms: 1607 - Prope&rties
    Forms: 2059 - Dra&w Table
    Full Screen: 178 - &Close Full Screen
    Edit Picture: 299 - &Adjust Margins
    Edit Picture: 922 - &Close Picture
    Visual Basic: 186 - &Macros...
    Visual Basic: 184 - &Record New Macro...
    Visual Basic: 3627 - &Security...
    Visual Basic: 1695 - &Visual Basic Editor
    Visual Basic: 548 - Control T&oolbox
    Visual Basic: 1605 - &Design Mode
    Visual Basic: 3631 - Microsoft Script &Editor
    Stop Recording: 2186 - Stop &Recording
    Stop Recording: 185 - &Pause Recording
    Mail Merge: 6926 - &Main document setup
    Mail Merge: 2246 - &Open Data Source
    Mail Merge: 6349 - &Mail Merge Recipients
    Mail Merge: 6346 - &Insert Address Block
    Mail Merge: 6347 - &Insert Greeting Line
    Mail Merge: 6348 - &Insert Merge Fields
    Microsoft: 263 - Microsoft &Excel
    Microsoft: 267 - Microsoft Office &PowerPoint
    Microsoft: 6225 - &Microsoft Outlook
    Microsoft: 264 - Microsoft &Access
    Microsoft: 266 - Microsoft Visual &FoxPro
    Microsoft: 269 - Microsoft P&roject
    Microsoft: 265 - Microsoft &Schedule+
    Microsoft: 268 - Microsoft Pu&blisher
    Ok DENIED!! lol.. that list was over 38K characters so VBF Freaked on me..
    I Shortened the list to a few so u can see...

    basically.. start work.. ALT F11... add a module.. drop that code in.. then run it..
    switch back to your doc and u will see the whole list...

    Have fun
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    6

    Re: How do I Find control IDs in Visual Basic for Applications for office 2003?

    Thanks Static.

    I followed your directions and was able to generate a list in word of many ID's. However I can't seem to find a few specific ID's in the list that I'm huntin for. In an effort to locate these specific codes I noticed:

    This page references a command that is supposed to list a single command:
    Finding a single control ID
    VB Code:
    1. ? commandbars("menu bar").controls("file").controls("save as...").id

    According to the page I got it from, this code is supposed to let me find the exact ID I need (and I can change the text in the code so as to find what ever ID I want).. however when I paste this code in VB insert>module and hit run, the same way I did with the code you gave me it doesn't work. It asks me to create a macro and then after I name it and run it again I get "compile error".

    What am I missing?

  4. #4
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: How do I Find control IDs in Visual Basic for Applications for office 2003?

    VB Code:
    1. Debug.Print Application.CommandBars("Menu Bar").Controls("&File").Controls("Save &As...").ID
    748 apparently

  5. #5

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    6

    Re: How do I Find control IDs in Visual Basic for Applications for office 2003?

    Quote Originally Posted by bushmobile
    VB Code:
    1. Debug.Print Application.CommandBars("Menu Bar").Controls("&File").Controls("Save &As...").ID
    748 apparently
    I appreciate the help but that seems to not work either.. This is what I did.
    I copied your code above, Ran word 2003, opened VB 6.3 (alt+f11), Clicked on Insert>module, pasted the code in that window, clicked run, gave the macro and ID of "ID" or "TEST", then I hit run again and I get:

    Compile error:
    Invalid outside procedure


    Any thing else I can try?

  6. #6
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: How do I Find control IDs in Visual Basic for Applications for office 2003?

    Do this:

    Ran word 2003, opened VB 6.3 (alt+f11), Clicked on Insert>module
    so far so good.

    Now copy and paste:

    VB Code:
    1. Private Sub GetID()
    2.     MsgBox Application.CommandBars("Menu Bar").Controls("&File").Controls("Save &As...").ID
    3. End Sub

    And then press F5. Voila!

    Note: If your going to try and find other IDs as well, remember that the names are case sensitive and that any letter that is underlined should be preceeded with an ampersand (&).

  7. #7
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926

    Re: How do I Find control IDs in Visual Basic for Applications for office 2003?

    Quote Originally Posted by ryeookin
    What am I missing?
    OK, I know you got your answer, but anyway.
    You were missing this line:
    You use the Immediate window in VBA to look up the control ID for a single item on a menu.

    To use this oneliner, you need to paste it in the immediate window, and not in the code window.

    After you press ALT+F11, there is at the bottom of the screen a window with the caption "Immediate". If you don't see it, try pressing CTRL+G or select View--> Immediate Window from the menu.
    Paste the one-liner in this window, and press enter.
    Frans

  8. #8
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: How do I Find control IDs in Visual Basic for Applications for office 2003?

    Good catch Frans. I didn't even read that section of the post

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How do I Find control IDs in Visual Basic for Applications for office 2003?

    Moved to Office Development

  10. #10

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    6

    Re: How do I Find control IDs in Visual Basic for Applications for office 2003?

    Quote Originally Posted by bushmobile
    Do this:

    VB Code:
    1. Private Sub GetID()
    2.     MsgBox Application.CommandBars("Menu Bar").Controls("&File").Controls("Save &As...").ID
    3. End Sub

    And then press F5. Voila!
    Thanks a lot Bushmobile!
    It works and I can get the ID's for word 2003 that I needed so I can and am locking down word now.

    Also thanks Frans C! I had no clue.. thanks for clearing that up!
    That was the missing link it appears.. as now those codes I found from:
    Finding a single control ID
    The command (when placed in the immediate window and a carrige return hit)
    VB Code:
    1. ? commandbars("menu bar").controls("file").controls("save as...").id
    Now works in word!

    However this seems to only work in word though and I need to lock down all of office 2003.. Do you guys know what modified version of the VB command you gave me above would work for the other office programs (access, excel, power point, and publisher) so I can lock them down as well?



    On a side note/rant. I see that all the code above works in all VB 6.3 that comes with office 2003.. even on pcs that I didn't install VBA on. Now that page I mentioned above of microsofts told me I had to install VBA to get these control ID's which apparently isn't the case.. so I'm kinda miffed at them for telling me I had to buy that VBA cd which cost me 16 bucks. Jerks.. Could be worse I guess.

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How do I Find control IDs in Visual Basic for Applications for office 2003?

    VB 6.3 is VBA.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  12. #12

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    6

    Re: How do I Find control IDs in Visual Basic for Applications for office 2003?

    Quote Originally Posted by RobDog888
    VB 6.3 is VBA.
    Now I find out..

  13. #13
    New Member
    Join Date
    Mar 2006
    Posts
    1

    Re: How do I Find control IDs in Visual Basic for Applications for office 2003?

    hi there :-)

    how can i recieve the id's for the checkboxes in the settings dialog, in the groupbox grammar?

    cheers FunteX! :-)

Posting Permissions

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



Click Here to Expand Forum to Full Width