These examples show how to use OleAutoClient to gather a list of Microsoft Word "Normal" template macros and run a Word macro from dBASE Plus. Examples are provided for both Word 95 and Word 97.

Word 95 example 1:

// Assign a new Word.Basic object.

// If Word is already running, the object uses the running instance.

// If Word is not running, an instance is created, but hidden.

// To make the instance visible, use the Word AppShow() command.

w = new OleAutoClient("word.basic")

w.AppShow( )

// Clear the Command window,

// list all macros and descriptions in the Normal template
clear

for m = 1 to w.countmacros(0)

   n = w.macroname(m, 0) 

   ? n 

   ? w.macrodesc(n) 

next count

// to run a macro named "Macro1"

w.toolsmacro("Macro1",true)

// Dismiss the object. If Word was already open when this routine was run, it remains open but releases the object. If you opened Word with this routine, the object is released and Word is removed from the task list. If you also made Word visible with AppShow( ), the app is closed.

w = ""

Word 95 example 2. Scenario: A form offers lists containing two corresponding associative arrays of Word documents and available printers. When the user selects a document and a printer, a single button opens the selected Word document, shows Word’s printer set up dialog, prints the document and then closes the document.

function printButton_onClick()

   local w 

   w = new OleAutoClient("word.basic") 

   w.FileOpen(this.form.aDocs[ this.form.docSelect.value ]) 

   w.FilePrintSetup(this.form.aPrinter[ this.form.printerSelect.value ]) 

   w.FilePrint() 

   w.FileClose() 

Word 97 example (equivalent to 95 example 1):

// Assign a new Word application object.

// If Word is already running, the object uses the running instance.
// If Word is not running, an instance is created, but hidden.
// To show it, you can use Word's Visible property.

w = new OleAutoClient("Word.Application.8")

w.Visible = true

// Clear the Command window,

// list the names of all macros (grouped into VBComponents in Word 97)
// in the Normal template.
clear

for i = 1 to w.NormalTemplate.VBProject.VBComponents.Count

   ? w.NormalTemplate.VBProject.VBComponents.Item(i).Name

next i

w.Application.Run("Macro1")

w.Application.Quit()