To run this example you have to catalog the Microsoft Word Object Library under a module name ComCatalogation
The PBL methods included in this example are part of the WordExample project under the sample directory of your Studio installation. The input.doc Word document used in the second example is under the WordExample project directory, move it to 'C:\tmp' to make the process work or modify the line in the PBL to the real location of the file in your installation.
The PBL below, shows how to create and fill with text a Word file. This PBL is the one corresponding to the activity 'CreateWordDocument' of the 'Word Document Creation Example' process.
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. This PBL is the one corresponding to the activity 'Input Word Document Example' of the analog process.
// 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