CreateEventProc Method

Applies To

CodeModule object.

Description

Creates an event procedure.

Syntax

object.CreateEventProc(eventname, objectname) As Long

The CreateEventProc syntax has these parts:

Part

Description

object

Required. An object expression that evaluates to an object in the Applies To list.

eventname

Required. A string expression specifying the name of the event you want to add to the module.

objectname

Required. A string expression specifying the name of the object that is the source of the event.


Remarks

Use the CreateEventProc method to create an event procedure. For example, to create an event procedure for the Click event of a Command Button control named Command1 you would use the following code, where CM represents a object of type CodeModule:

TextLocation = CM.CreateEventProc("Click", "Command1")
The CreateEventProc method returns the line at which the body of the event procedure starts. CreateEventProc fails if the arguments refer to a nonexistent event.

See Also

AddFromString method, DeleteLines method, InsertLines method, ProcBodyLine method, ProcCountLines method, ProcOfLine method, ProcStartLine method, ReplaceLine method.

Example

The following example uses the CreateEventProc method to create the Button_Click procedure.

Debug.Print Application.VBE.SelectVBComponents.CodeModule.CreateEventProc( _
    "Click", "Button")