nNote We did not tell our code to format the body text in Normal style, did we? The default behavior of
Word??™s heading styles is to format text at the following paragraph marker to Normal style (saving us a line
of code in the process!).
Figure 8-4. The report heading and text
nNote The formatting of the Heading 1 and Normal styles may differ in your Word installation.
CHAPTER 8 n OFFICE INTEGRATION 294
8. Navigate back to the main Excel window and click OK on the message box to let the
code finish running, as shown in Figure 8-5.
Figure 8-5. The message box stops the code so that we can check results.
9. Click No when prompted to save theWord document (unless you really want it).
Adding Charts to the Report
We??™ve seen now that our code works. Word opened and the heading section of the report displayed
successfully. Now let??™s return to the VBE and add our charts and their descriptive text.
We have three charts to insert and three sets of descriptive text. In this section, we will
add a loop that will do the following:
??? Insert a blank line between each section
??? Insert the descriptive text
??? Insert the chart
1. In the MakeWordDoc subroutine, place the cursor at the beginning of the End With
statement.
2. Press Enter.
3. Move the insertion point into the blank line you just created and add the following
lines of code:
For i = 1 To 3
.Selection.TypeParagraph
InsertText i
InsertChart i
Next i
I??™ve created a couple of helper functions to insert the text and charts according to the
index passed into the procedure.
Pages:
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277