Controlling Word from Excel

The example in Figure 23-2 demonstrates an automation session by using Word. The MakeMemos procedure creates three customized memos in Word and then saves each memo to a separate file. The information used to create the memos is stored in a worksheet.

Figure 23-2:

Word automatically generates three memos based on this Excel data.

. nl®

A

. 81

Wi

a

m

A

1

Regionl

Ï134.5ÈÈ

2

Region2

122

$127-;B83

Create Word Memos Using Data on This Worksheet

3-

Reciion3

2D3

¡KB8;3"S3

gjfn

5

fi

r&iessatfe:

The monthly sales data for your region is listed below. This information was obtained From the central database. Please call if you have any questions.

J

"i

S

9

in

>:f

h * t H[\Sheet]

jm

Word automatically generates three memos based on this Excel data.

The code for the MakeMemos procedure is too lengthy to list here, but you can go to this book's Web site to check it out.

The MakeMemos procedure starts by creating an object called WordApp. The routine cycles through the three rows of data in Sheetl and uses Word's properties and methods to create each memo and save it to disk. A range named Message (in cell E6) contains the text used in the memo. All of the action occurs behind the scenes: Word is not visible. Figure 23-3 shows a document created by the MakeMemos procedure.

0 0

Post a comment