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?
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:
Private Sub PrintIDs()
Dim CBTN As CommandBarButton
Dim CBR As CommandBar
On Error Resume Next
For Each CBR In Application.CommandBars
For Each CBTN In CBR.Controls
Selection.TypeText CBR.Name & ": " & CBTN.ID & " - " & CBTN.Caption
Selection.TypeParagraph
Next
Next
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
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:
? 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?
Re: How do I Find control IDs in Visual Basic for Applications for office 2003?
VB Code:
Debug.Print Application.CommandBars("Menu Bar").Controls("&File").Controls("Save &As...").ID
748 apparently
Re: How do I Find control IDs in Visual Basic for Applications for office 2003?
Quote:
Originally Posted by bushmobile
VB Code:
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?
Re: How do I Find control IDs in Visual Basic for Applications for office 2003?
Do this:
Quote:
Ran word 2003, opened VB 6.3 (alt+f11), Clicked on Insert>module
so far so good.
Now copy and paste:
VB Code:
Private Sub GetID()
MsgBox Application.CommandBars("Menu Bar").Controls("&File").Controls("Save &As...").ID
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 (&).
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.
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 :blush:
Re: How do I Find control IDs in Visual Basic for Applications for office 2003?
Moved to Office Development
Re: How do I Find control IDs in Visual Basic for Applications for office 2003?
Quote:
Originally Posted by bushmobile
Do this:
VB Code:
Private Sub GetID()
MsgBox Application.CommandBars("Menu Bar").Controls("&File").Controls("Save &As...").ID
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:
? commandbars("menu bar").controls("file").controls("save as...").id
Now works in word! :thumb:
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.. :rolleyes: Could be worse I guess.
Re: How do I Find control IDs in Visual Basic for Applications for office 2003?
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.. :cry:
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! :-)