Declaring and Using Event Procedures in VBScript

Microsoft Office Web Components Visual Basic

Declaring and Using Event Procedures in VBScript

You declare event procedures in Visual Basic by using the Private and ByVal keywords and arguments with explicit type declarations, as shown in the following example.

Private Sub Spreadsheet1_MouseOver(ByVal Button As Long, ByVal Shift As Long, ByVal Target As Range)
		

This procedure declaration will not work in VBScript because VBScript does not use these keywords and because all arguments are passed as Variant. Instead, you declare event procedures in VBScript simply by using the event name and argument names, as shown in the following example.

Sub Spreadsheet1_MouseOver(Button, Shift, Target)
		

The argument names themselves are simply a convention in any container (you could use any argument names).

Caution  Some script editors (including Microsoft Script Editor) do not fill in the argument list when they create an event procedure. To ensure that your event procedure runs correctly, consult the Object Browser or the appropriate event topic in Help, and fill in the argument list yourself.