SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 261 | Next

Jim DeMarco

"Pro Excel 2007 VBA"

"
CHAPTER 8 n OFFICE INTEGRATION 290
Case 3
sBody = "Sales in this category were above average " ??
& "for the first third of the year. February and April " ??
& "showed spikes due to holidays."
End Select
GetSubjectBody = sBody
End Function
5. Save the project.
In a production application, you are probably not likely to store these string values in
your VBA code. For the purposes of our examples, I??™ve included the text here, but a more realistic
scenario would be if this information came from a database, an XML or text file, or even a
worksheet in an Excel project.
The last subroutine we added, GetSubjectBody, takes a parameter named Index. This is
used to match and display the correct text for the corresponding chart.
Let??™s move back to StandardModule1 and resume programming our Word report.
Creating an Instance of Word
Before we begin, let??™s outline the steps involved in creating a report with text and charts in
Word from Excel VBA code:
1. Open the Word application.
2. Create a new Word document.
3. Add formatted headings and text.
4. Add charts with formatted headings and text.
5. Display Word and the new report.
Let??™s begin. Our first tasks are to open an instance of the Word application and load a new
document into that instance.
1. In the MakeWordDoc subroutine, add the following statements:
Set m_oWordApp = CreateObject("Word.Application")
Set m_oWordDoc = m_oWordApp.Documents.Add
We are using the CreateObject function to create an instance of the Word application.


Pages:
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273