One is when you want to use an existing
instance of an application object that is already loaded. The other is when you want to start an instance of an
application with a file loaded.
The syntax for using GetObject is GetObject(pathname, class), where pathname is the path to
a Microsoft Office document. The class parameter is not required in this case, as GetObject will find which
application to launch. If no file name is given, the class parameter is required. The class parameter takes the
same object class identifier as the CreateObject function.
2. Next, fill the variables with title and body text by adding the following lines of code:
sTitle = GetTitle
sBody = GetTitleBody
3. Then, use the Word Application object to insert the title and body text into the Word
document, by adding the following code to the MakeWordDoc subroutine:
With m_oWordApp
.Selection.Style = .ActiveDocument.Styles("Heading 1")
.Selection.TypeText sTitle
.Selection.TypeParagraph
.Selection.TypeText sBody
End With
CHAPTER 8 n OFFICE INTEGRATION 292
This code defines the document style for the first line of text and inserts the title text.
Next, we add a new paragraph break and insert the report??™s descriptive body text.
Before we begin inserting our charts, let??™s add some cleanup code and take a quick look at
our progress by running and displaying Word from the VBE.
4. Add the following code after the With...End With block:
m_oWordApp.Visible = True
MsgBox "word s/b open now"
m_oWordApp.
Pages:
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275