O'Reilly logo

VBScript in a Nutshell by Ron Petrusha, Paul Lomax, Matt Childs

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Running Your Code

The “hook” that allows your code to run is an event handler or an event procedure . Outlook recognizes particular external events—like an instance of a form being opened, or the user clicking on the Send button to send a mail message—and responds by firing an event. If a procedure exists to handle that event, its code is executed automatically. The event procedure can in turn call other procedures or functions, which can also call other procedures and functions, and so on.

Using VBScript, you are able to access only form-level events and control-level events; events at other levels, such as the application or even the Items collection level, cannot be trapped within the scripted environment. You can examine a list of some of the available events in the VBScript editor by selecting Script Event Handler. The editor opens the Insert Event Handler dialog like the one shown in Figure 6.4. If you select one of the events from the list box, the editor automatically creates the code shell for the event procedure. For example, if you were to select the Open item (which is fired just before a form is opened) in Figure 6.5, the editor would automatically generate the following code:

Function Item_Open( )

End Function
The Insert Event Handler dialog

Figure 6-4.  The Insert Event Handler dialog

Note that Outlook identifies the object whose Open event is being fired as " Item.” Each form represents a particular ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required