To run this example you have to catalog the Microsoft Word Object Library.
The PBL below, shows how to create and fill with text a Word file.
filename = "C:\\WordTest" + id.number + ".doc" Application.visible = false // get ready to use Word worddocs = Application.documents // create a new Word document worddoc = add(worddocs) // find something specific in the document. // in this case there isn't anything, // but the rangevar variable is still needed // for the next command which inserts the text. rangevar = range(worddoc) // tell Word where you want to put the sentence. // I say after rangevar, but as you know from above, // that isn't very specific. insertAfter rangevar using text = sentence + "\nFuego is the greatest software ever!" // save as the filename you want. // We built the name somewhat unique in a variable saveAs worddoc using fileName = filename // close the newly saved document close worddoc // quit quit Application
The PBL below, shows how to complete form fields in a Word file used as template, and saved as a new file.
// Initialize variables custName = customerName worddocs = wordappl.documents Application.visible = false // Open Word file open worddocs using fileName = "C:\\tmp\\input.doc" returning worddoc // Initialize the form fields into their object wordformfields = worddoc.formFields // Select the form field you want to work on item wordformfields using index = "Text2" returning wordformfield // Set the value of the form field you selected wordformfield.result = custName // Save as a different Word file saveAs worddoc using fileName = "C:\\tmp\\result.doc" // Quit Word quit wordappl