4.2 Getting to Word

Getting to Word

Before you can work with Word, you need an object reference to the Word Automation server or to a specific object in Word. Two VFP functions let you access Word. CreateObject() opens a new instance of Word and returns a reference to it, like this:

oWord = CreateObject("Word.Application")

Figure 1. The Word object model. The Help file offers a global view of Word s structure.

GetObject() is a little more complex. It takes either of two parameters, which reflect two approaches to providing a reference to Word. If you pass it the name of an existing document, it checks whether or not Word is already open. If not, it opens Word. Either way, it opens the specified document and returns a reference to the document:

oDocument = GetObject("d:\writing\books\automation\chapter4.doc")

If you omit the first parameter to GetObject() and specify the Word Automation server as the second, it looks for an open instance of Word and returns a reference to that instance:

oWord = GetObject(, "Word.Application")

If Word isn t open, an error message is generated.

See Chapter 3, "Visual FoxPro as an Automation Client," for more general information on CreateObject() and GetObject() and their use with the Office applications.

 

Copyright 2000 by Tamar E. Granor and Della Martin All Rights Reserved



Microsoft Office Automation with Visual FoxPro
Microsoft Office Automation with Visual FoxPro
ISBN: 0965509303
EAN: 2147483647
Year: 2000
Pages: 128

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net