Objective
The objective of this practice problem is for the user to demonstrate an understanding of the word commands discussed in the previous section by creating an automation that utilizes said commands. The commands covered in the previous section were the Create Word Application, Append Text, Append Image, Replace Text, Read Document, Export to PDF, Save Document As and Close Word Application commands. In the future, these commands may be implemented into other practice problems.
Scenario
An employee at ABC space organization is working on one of the biggest upcoming projects of NASA. The employee needs to update a specific project file from the system with new piece of information collected and create a new pdf file with project related details extracted from another piece of document.
Prerequisites
The user must use two pre-existing word documents (.docx) to use before starting work on the solution. The word application/documents must be closed when the process begins. Below is a screenshot of the word documents that were created for this problem. Feel free to recreate it or create a sample unique document. Feel free to delete this file when finished with the exercise, although this will mean that the automation cannot be run again.
Document 1:
Document 2:
Practice Problem Requirements
The user must create an automation that performs the following tasks:
  • Opens a word document (existing file) that is visible while the automation is running.
  • Append new text data collected into it. (Any logical text value)
  • Append an image to the document. (Similar logic)
  • Replace existing data in the document. (Replace any existing data with new values)
  • Create a new blank document along with creating and accessing another document to extract the data from.
  • Read/Extract the data from the second document and write it into the blank document created.
  • Export the newly appended document into PDF and save the word document.
  • Save a copy of the document with a different name in a separate folder (the user can decide which folder the file is saved to if it is not the original folder)
  • Close all the word Instances once the other commands have been completed.

Problem Difficulty: Medium
Solution will be provided on the next page with a brief explanation.

Solution
The code for the solution has been provided below.
As a quick summary:

Step 1: The Create Word Application command must be called first because it tells the automation that it needs to work with word document. The visibility and close Instances fields can both be set to yes or otherwise.

Step 2: The Open document command specifies which file and its location to the automation so that it can open correct file from the system.

Step 3: Append Text command adds new text to the pre-existing document and append image adds a new image to the document.

Step 4: To update/replace existing data in the document, Replace command is used to find what needs to be changed with what the new values will be.

Step 5: Close the word application to ensure that the task to update this document is completed.

Step 6: Create & Open two new documents; one blank to add values to it and other from the system to extract values from.

Step 7: Extract the data in the second document using the Read command and store it in a variable of choice.

Step 8: Append the extract data into the Blank document and convert it into a PDF file.

Step 9: The Save document as command will allow the specified word file (Blank one) to be saved under a user designated name in the specified file location.

Step 10: The Close word application command will allow the word applications to be closed as they are no longer needed. The Save on Close field is set to no because the files have already been saved.

Newsletter Bot

Lets stay in touch!

Join our weekly newsletter and follow us on social media.

Contact Sales
Call Our Experts!