Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

writing event handlers in VBA

Status
Not open for further replies.

NullCharacter

Programmer
Oct 2, 2006
1
US
I need a basic description of how to write an event handler in VBA. I've used C and C++ before, but passing arguments in VBA and creating event handlers seems confusing. Is there a short white paper on this? I have "Excel VBA for Dummies", but maybe I am even dunmmer since it doesn't really cover this topic much.

Thanks for all help.

John
 
This is really the VB rather than the VBA forum. However, to write an event handler, you simply need to use a particular naming convention, and you must use it as well. There isn't any way to specify a proc as handling a given event, and this is probably the source of your confusion.

In VB and in VBA, the convention is Sub ClassName_EventName(arglist), where ClassName is the name of the class (control) raising the event, and the event name and argument list are the actual event raised and the list of arguments defined by the class raising the event. For a simple example: Sub Command1_Click() is the event handler for a command button called Command1.

The particular IDE that you're working with will have a place where you can find a list of the available classes and potential events to be handled, select one such, and automatically place a template for the handler in your code. In VB, you simply need to double click on a control, and a default event handler template will show in your code. For example, double clicking on a command button in your IDE will place its click event in the code.

For more specific information, you will want to repost your question in the forum for the application that you're doing VBA code in. Also, googling to "VBA event handler" shows lots of articles.

HTH

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top