When I want to write event code in a Workbook, I Alt-F11 to open the VBE, Cntl-R to open the Project Explorer, arrow to the class module in which the code will go, and… Then, as far as I can tell, I have to use my mouse and the dropdowns at the top of the module to insert the Sub and End Sub lines.
I could just type them in, but I would to get the arguments just right or the VBE wouldn’t like it. It would be nice if the Insert > Procedure menu item had a provision for event code.
The best solution I could muster is to create text files that contain the code I want. I have two text files in my Office folder (Program FilesMicrosoft Office 2000Office is the default folder for Insert > File) called SheetEvents.txt and WorkbookEvents.txt.
SheetEvents contains the Worksheet_Change and Workbook_SelectionChange events. WorkbookEvents contains Open, BeforeClose and BeforeSave. Those are the events I use most often. I thought about making a separate file for each event, but I decided to just put the most common ones in a file and delete anything I don’t need. Creating the text files was a simple copy and paste operation into Notepad after I used the dropdowns to get the events I wanted.
I hate how when you select an item on the left it automatically inserts what it wants from the right.
For example when I create a new user form and I choose “UserForm” from the left dropdown it automatically inserts “UserForm_Click”. It would be nice if it would let me pick what I want from the right before inserting anything.
MZ Tools 3.0 for VBA has two functions which might help. The Add Procedure function does not, afaik, add an event procedure, BUT the Code Template allows the user to define pre-defined code segments – and just for Dick, you can define a shortcut for each code segment.
BTW, I find MZ Tools provides some really useful functions. wouldn’t code without it.
Bill: I agree. I’ve told Microsoft that their choice of default events is poor. I don’t know if they listened, though.
Alex: I used to have MZ Tools but had a problem that it caused. I don’t know why I never re-installed it, but I think I will.
>> I have to use my mouse and the dropdowns at the top of the module
I don’t know if you’re looking for a keyboard shortcut, Dick, but Ctrl-F2 activates the left dropdown and a Tab will then take you to the right.
Jim: Hooray! That’s just what I wanted.
Dick –
I can’t believe you’d add a whole layer of infrastructure (text files with event procedure stubs) just to avoid using the mouse. Though I’m glad Jim saved you from this.
– Jon
You can’t? I miss the old TRS-80 days, I guess.
Man, you gotta adapt to the times.
[quote]
I miss the old TRS-80 days, I guess.
Yeah, what a hoot it was: 128k and everything you did was a programming process. Kind of like crawling: you were forced to learn to walk; because you were soon leaving the top two inches of your forehead on the bottom of the coffee table… :-D