Microsoft Office 2000/Visual Basic Programmer's Guide |
One simple but very powerful method you can use to customize the way Word works is to run your own VBA procedure in place of a built-in procedure. Doing this lets you customize the behavior of Word in any way you can imagine.
There is no limit to the kinds of things you can do and the kinds of built-in behaviors you can change. You could save documents created by using your custom template to a different directory than documents created by using Normal.dot. You could modify the File New command to create custom document properties for every new document. You could display your own custom dialog box instead of the Word dialog box normally displayed in response to a menu command. You could also let the built-in command run and then detect whether a user made certain selections from a Word dialog box.
The first thing you have to do is figure out which procedure Word runs to perform a built-in action. This is easy to do for all built-in menu commands. If you press ALT+CTRL+PLUS SIGN (+) on the numeric keypad (not the PLUS SIGN on the keyboard) and then click the menu item you want to investigate, Word displays the Customize Keyboard dialog box, which shows the name of the built-in procedure in the Commands list. For example, in Figure 5.5, you can see that Word runs the FileSaveAs procedure whenever a user clicks Save As on the File menu.
Figure 5.5 The Customize Keyboard Dialog Box
There are three ways you can substitute your own procedure for a built-in Word procedure: