You don't *call* the event procedure shown at step 4. Event procedures are
called automatically when the given even happens. You might be more familiar
with the event procedures in a UserForm (UserForm are special kinds of class
modules, and -- in this respect -- work in pretty much the same way.) If you
have a TextBox on your UserForm, you can write an event procedure --
textbox1_Click() -- which is called automatically when the textbox's click
event happens. Similarly, the Word Application object and the Document
object have trappable events (have a look at the object browser -- events
are the functions with a little lightning bolt icon.
And, most salient in this case, command bar objects have click events, which
you can trap: the click event is fired when the user clicks the control: and
the toolbars mechanism supplies the Ctrl argument.
> Hi
>
[quoted text clipped - 63 lines]
> Thanks again
> Mike
Mike Boson - 16 Aug 2005 14:12 GMT
Thanks but sorry, I'm as confused as I was at the beginning.
I am familiar with event procedures, but I can't figure out how to use the
procedure in step 4 (let alone instantiating the class properly). I've tried
putting it in a module but nothing happens. The event procedure has
arguments that need to be supplied - so how do they get supplied?
There were a bunch of other questions I asked in my post that I'm sure
affect whether I can get the code to work...
Any guidance or enlightenment from anyone would be *greatly* appreciated.
TIA
Mike
> You don't *call* the event procedure shown at step 4. Event procedures are
> called automatically when the given even happens. You might be more familiar
[quoted text clipped - 77 lines]
> > Thanks again
> > Mike
Jezebel - 17 Aug 2005 07:31 GMT
1) The event procedure must be in a *class* module, not an ordinary module.
2) To instantiate the class: create an ordinary module with code along these
lines ---
Private mClassVar as clsMyClass 'Module-level
variable, 'clsMyClass' is whatever you called your class module
'Use AutoExec if you want the class to instantiate automatically when the
template loads
Public Sub AutoExec()
Set mClassVar = new clsMyClass 'Instantiate the
class. Note that the class Initialize function runs at this point
End Sub
3) The arguments to the event procedure are provided automatically by the
event itself. You don't have to do anything about these.
> Thanks but sorry, I'm as confused as I was at the beginning.
>
[quoted text clipped - 106 lines]
>> > Thanks again
>> > Mike
Mike Boson - 17 Aug 2005 11:38 GMT
That's great, now I get it! Another question if you don't mind?
How should I identify a control that doesn't have a ID number? I modified
the code below (from MS KB) to return the ID numbers of all controls, but:
Some menu controls don't turn up in the results (for instance File>Close).
Are those just not available or is there another way to trap them?
Other controls that have been added by add-ins or manually all have an ID of
"1". Is the only way to identify those customised menu items by using their
Tag?
Thanks for any help...
Mike
Sub FindFaceIDsWordDocument()
'This code prints the information to a new Word document.
Dim c As CommandBar, ctl As CommandBarControl
Application.Documents.Add
For Each c In Application.CommandBars
For Each ctl In c.Controls
Selection.TypeText "CommandBar Name: " & c.Name & _
" | Caption: " & ctl.Caption & " | ID: " & ctl.ID
Selection.TypeParagraph
Next
Next
End Sub
RESULTS>>> (edited)
CommandBar Name: Standard | Caption: New &Blank Document | ID: 2520
CommandBar Name: Standard | Caption: &Open... | ID: 23
CommandBar Name: Standard | Caption: &Save | ID: 3
CommandBar Name: Standard | Caption: &Mail Recipient | ID: 3738
CommandBar Name: Standard | Caption: &Print | ID: 2521
CommandBar Name: Standard | Caption: Print Pre&view | ID: 109
CommandBar Name: Standard | Caption: Print to PaperPort (PDF) | ID: 1
CommandBar Name: Standard | Caption: &Spelling and Grammar... | ID: 2566
CommandBar Name: Standard | Caption: Cu&t | ID: 21
CommandBar Name: Standard | Caption: &Copy | ID: 19
CommandBar Name: Standard | Caption: &Paste | ID: 22
CommandBar Name: Standard | Caption: &Format Painter | ID: 108
CommandBar Name: Standard | Caption: &Undo VBA-Selection.TypeParagraph | ID:
128
CommandBar Name: Standard | Caption: Can't &Redo | ID: 129
CommandBar Name: Standard | Caption: Hyperl&ink... | ID: 1576
CommandBar Name: Standard | Caption: &Tables and Borders Toolbar | ID: 916
CommandBar Name: Standard | Caption: &Insert Table... | ID: 333
CommandBar Name: Standard | Caption: &Insert Excel Spreadsheet | ID: 142
CommandBar Name: Standard | Caption: &Columns... | ID: 9
CommandBar Name: Standard | Caption: &Drawing | ID: 204
CommandBar Name: Standard | Caption: &Document Map | ID: 1714
CommandBar Name: Standard | Caption: &Show All | ID: 119
CommandBar Name: Standard | Caption: &Zoom: | ID: 1733
CommandBar Name: Standard | Caption: Microsoft Word &Help | ID: 984
CommandBar Name: Standard | Caption: Insert Contact | ID: 1
[etc]
Jezebel - 17 Aug 2005 11:55 GMT
A simpler approach if you're adding you're on controls is to specify the
function that is called when they run (as opposed to using an event). Then
you can use ActiveControl to identify the actual control that was activated,
and check its tag. There's an additional property (the name of which escapes
at the moment) you can use if you need a second piece of information, eg if
you have a control array.
Also, can't you set the ID value of the controls you add? (Can't remember
that off-hand either...)
> That's great, now I get it! Another question if you don't mind?
>
[quoted text clipped - 60 lines]
> CommandBar Name: Standard | Caption: Insert Contact | ID: 1
> [etc]
Mike Boson - 18 Aug 2005 11:11 GMT
Thanks for the idea about ActiveControl. The problem I have with controls
that have ID=1 is that a lot of them are in third party add-ins and I don't
have any control over their IDs. Those third party controls don't have Tags
either. So the only way to identify them would be ActiveControl I guess...
Thanks again.
> A simpler approach if you're adding you're on controls is to specify the
> function that is called when they run (as opposed to using an event). Then
[quoted text clipped - 70 lines]
> > CommandBar Name: Standard | Caption: Insert Contact | ID: 1
> > [etc]
Jezebel - 18 Aug 2005 12:01 GMT
As long as you tag your own controls, then you can safely ignore the tagless
ones?
> Thanks for the idea about ActiveControl. The problem I have with controls
> that have ID=1 is that a lot of them are in third party add-ins and I
[quoted text clipped - 92 lines]
>> > CommandBar Name: Standard | Caption: Insert Contact | ID: 1
>> > [etc]
Mike Boson - 18 Aug 2005 20:27 GMT
I wish I could ignore the tagless ones but some of them are the ones I need
to catch. Oh well. Guess I'll have to get to the developers and ask them
what the macro names are for the relevant controls so I can use
ActiveControl. And maybe ask them to Tag or ID their controls in the future.
Thanks again for your help.
Mike
> As long as you tag your own controls, then you can safely ignore the tagless
> ones?
[quoted text clipped - 95 lines]
> >> > CommandBar Name: Standard | Caption: Insert Contact | ID: 1
> >> > [etc]