O'Reilly logo

Writing Word Macros, Second Edition by Steven Roman PhD

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

Example: A Fax Cover Sheet

A little programming makes it easy to automate the process of creating fax cover sheets. In particular, we want a dialog box that opens automatically whenever the user creates a new document based on the fax cover sheet template, so we will include the UserForm module in this template’s project.

The first step is to create the template, as shown in Figure 20-4. Note that I have placed bookmarks in some of the table cells, as indicated by the words (Bkm) in Figure 20-4. (These words are not meant to be in the actual document, but are there to indicate where the bookmarks are placed.) These bookmarks are used by our code to place additional text. Their names are (from top to bottom in Figure 20-4) To, ToCompany, ToPhone, ToFax, Pages, Re, and Comments.

In order to get the form to open automatically when a new document is created, place code to execute the Show method of the form in the Document_New event for the template, as Example 20-5 shows.

Example 20-5. Inovking the Fax User Form

Private Sub Document_New()
    frmFaxCover.Show
End Sub
A fax cover sheet

Figure 20-4. A fax cover sheet

The dialog box is shown in Figure 20-5. Its controls and their non-default proper-ties are shown in Table 20-8.

Table 20-8. Controls and Their Nondefault Properties for the Fax Cover Sheet

Control

Property

Value

UserForm

Name

frmFAXCover

 

Caption

Fax

Frame

Caption

To:

Label

Accelerator

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