Replace Text in a Word Document
  • 29 Jul 2022
  • 3 Minutes to read
  • Dark
    Light

Replace Text in a Word Document

  • Dark
    Light

Article Summary

Overview

The following document demonstrates how to use the Replace Text in a Word Document step from the Toolbox > DATA > MS WORD category. This step gets bookmarks from a Word Document, replaces them with a desirable Text, and returns an updated Document File.

The Replace Bookmark with Text (Dynamic) step is very similar to the Replace Text in a Word Document step because it is a step that also searches for bookmarks to replace with the desired text. However, it requires several duplicate steps in a Flow to replace text in a Word Document. 

Example

Below is a chart of useful documents for this tutorial: 
Document with Bookmarks
Document with Tokens
Downloadable example to import into Decisions

(Please navigate to Import and Export Overview for more information on importing and exporting documents.)

Note on Word Document Files 
Note that presently, Word Documents created using an online or external document processor (such as Word 365 or Google Docs) other than Microsoft Word are incompatible for use with the Replace Text Workflow steps.

Failure to use a Word-generated document will result in unexpected results and failure to apply the specified changes. 

  1. Create a Flow. In the Flow Designer, drag a Show Form step from the Toolbox > FAVORITE STEPS section to the workspace and connect it to the Start step.
  2. >In the Properties panel, select PICK OR CREATE FORM.


  3. Click CREATE to create a new Form, select the default Form, and name it Invoice. Select CREATE.
  4. In the Form Designer, drag four Labels [Name, Company, Address, Number], four corresponding Text Boxes, and a Button [Submit] to the Form from the Toolbox > FAVORITES section.
  5. Save and Close the Form Designer to navigate back to the Flow.
  6. From the Toolbox > DATA > MS WORD, drag a Replace Text in a Word Document step to the workspace and connect it to the outcome of the Show Form step.
  7. Before configuring the Replace Text in Word Document step, drag and drop another Show Formstep into the workspace.
    1. Connect the Show Form step to the Done outcome of the Replace Text in Word Document step.
    2. In its Properties panel, select PICK OR CREATE FORM. Pick CREATE, name the Form [Download Document] and click CREATE.
    3. In the Form Designer, drag and drop the File Download [OutputDocumentFile] and Button [Done] components from the Toolbox > FAVORITES section.
    4. Save and Close the Form Designer.


  8. In the Flow Designer, connect the Done and Failed outcomes to the End step.
Depending on the document, the Replace Text in a Word Document step can replace text in two different modes under Properties > Configuration > Replace Mode.

Replace Mode: Bookmark

  1. With the Replace Text in Word Document step selected, in the Properties panel > CONFIGURATION, use the Pick Document File selector to pick the relevant Word Document File; in this example, the file is Decisions Invoice Bookmarks Example.
  2. Under INPUTS, configure each string to a Select From Flow mapping except _GoBack which will be set to an Ignore mapping.
  3. Connect each data field to its respective input.
  4. Select Debug from the Top Action Menu to test the Flow.
    1. Click START DEBUGGING and input Form information.
    2. Select Download File and open the file to observe the replaced bookmarks. 

Replace Mode: Token

  1. With the Replace Text in Word Document step selected, in the Properties panel > CONFIGURATION, use the Pick Document File selector to pick the relevant Word Document File; in this example, the file is Decisions Invoice Tokens Example.
  2. The INPUTS > [Company], [Full Address], [Name], [Number] will all be set to a Select From Flow mapping and mapped to the respective data fields.
  3. Properties > REPLACE TOKENS > Start of Token and End Of Token will define what the step looks for to replace within the Word Document, in this example it is square brackets ([]).

Debug

  1. The Flow is complete, select Debug from the Top Action Panel. 
  2. Click START DEBUGGING and input Form information.
  3. Select Download File and open the file to observe the replaced tokens.



Was this article helpful?