The following example uses objects from the Microsoft Word Object Library to create a table in a new document, RESM.DOC. The script adds a record displayed in the Buyers window of the Real Estate Sales Manager application to a row in the table.
local Word.Application app; local Word.Document document; local Word.Table wordTable; local Word.Range wordRange; {If Word is running, use it. Otherwise, create a new instance.} app = COM_GetObject("Word.Application"); if(app = null) then app = new Word.Application(); end if; {Make Word visible.} app.Visible = true; {Create a new document.} document = app.Documents.Add(); {Add a table with two rows and four columns to the document.} wordRange = document.Range(0,0); wordTable = document.Tables.Add(wordRange, 2, 4); {Set the values of the cells in the first row in the table.} wordRange = wordTable.Cell(1,1).Range; wordRange.InsertAfter("Buyer ID"); wordRange = wordTable.Cell(1,2).Range; wordRange.InsertAfter("Buyer First Name"); wordRange = wordTable.Cell(1,3).Range; wordRange.InsertAfter("Buyer Last Name"); wordRange = wordTable.Cell(1,4).Range; wordRange.InsertAfter("Phone"); {If record is not displayed, warn user. Otherwise, add the record.} if 'Buyer ID' = "" then warning "Please display a record in the Buyers window."; else wordRange = wordTable.Cell(2,1).Range; wordRange.InsertAfter('Buyer ID'); wordRange = wordTable.Cell(2,2).Range; wordRange.InsertAfter('Buyer First Name'); wordRange = wordTable.Cell(2,3).Range; wordRange.InsertAfter('Buyer Last Name'); wordRange = wordTable.Cell(2,4).Range; wordRange.InsertAfter(Phone); end if; {Close the document and prompt the user for a document name.} document.Close(Word.wdPromptToSaveChanges); {Close the application.} app.Quit(); {Clear the variables.} clear wordRange; clear wordTable; clear document; clear app;