activities
latest
false
Productivity Activities
Last updated Oct 23, 2024

Manage Word Documents

The example below explains how you can customize a Word document by reading the text from the file, displaying it in a message box, appending text, and replacing text without even opening Microsoft Word. The example uses activities such as Read Text, Append Text, or Replace Text in Document. You can find these activities in the UiPath.Word.Activities package.

This is how the automation process can be built:

  1. Open Studio and create a new Process.
  2. Download and extract the archive with the project in this example and copy the file document.docx to your project folder.
  3. Drag a Sequence container in the Workflow Designer.

    • Create the following variable:

      Variable Name

      Variable Type

      Default Value

      text

      String

      N/A
  4. Drag a Message Box activity inside the Sequence container.

    • Add the expression "This is the original document." in the Text field.
  5. Drag a Read Text activity below the Message Box activity.

    • Add the expression "document.docx" in the File path field.
    • Add the variable text in the Text field.
  6. Drag a Message Box below the Read Text activity.

    • In the Properties panel, select the Ok option from the Buttons drop-down list.
    • Add the variable text in the Text field.
    • Select the check box for the TopMost option. This always brings the message box to the foreground.
  7. Drag a Message Box below the previous Message Box activity.

    • In the Properties panel, select the Ok option from the Buttons drop-down list.
    • Add the expression "A new paragraph is added" in the Text field.
    • Select the check box for the TopMost option. This always brings the message box to the foreground.
  8. Drag an Append Text activity below the Message Box activity.

    • Add the expression "document.docx" in the File path field.
    • Add the following expression in the Text field: "Nulla eu arcu a urna ultrices scelerisque nec in lectus. Suspendisse iaculis cursus turpis. Sed sed nibh in augue molestie egestas sit amet ac justo. Suspendisse facilisis, mi scelerisque mattis elementum, leo nisi euismod turpis, sed consequat nibh nulla non ipsum. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean mauris risus, aliquam vel tristique blandit, consectetur ac nunc. Phasellus convallis dolor ligula, non auctor nulla lobortis sit amet. Nulla eu lectus fermentum, porttitor metus in, consectetur ex. Vivamus gravida justo et auctor fermentum. Cras nisl urna, blandit et elementum sit amet, sodales ut tellus. In sit amet semper lectus. Donec ac ipsum vel libero mattis porta vitae id velit. Nullam facilisis porttitor elementum. Ut congue tristique nisi, ornare porta enim mattis eu. Donec in lacus risus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.".
    • Select the check box for the New line option.
  9. Drag a Read Text activity below the Append Text activity.

    • Add the expression "document.docx" in the File path field.
    • Add the variable text in the Text field.
  10. Drag a Message Box below the Read Text activity.

    • In the Properties panel, select the Ok option from the Buttons drop-down list.
    • Add the value text in the Text field.
    • Select the check box for the TopMost option. This always brings the message box to the foreground.
  11. Drag a Message Box below the previous Message Box activity.

    • In the Properties panel, select the Ok option from the Buttons drop-down list.
    • Add the value "Replace all the occurrences of the word "lorem" with "REPLACED"" in the Text field.
    • Select the check box for the TopMost option. This always brings the message box to the foreground.
  12. Drag a Replace Text activity below the Message Box activity.

    • Add the expression "document.docx" in the File path field.
    • Add the value "REPLACED" in the Replace field.
    • Add the value "lorem" in the Search field.
  13. Drag a Read Text activity below the Replace Text activity.

    • Add the expression "document.docx" in the File path field.
    • Add the variable text in the Text field.
  14. Drag a Message Box activity below the Read Text activity.

    • In the Properties panel, select the Ok option from the Buttons drop-down list.
    • Add the value text in the Text field.
    • Select the check box for the TopMost option. This always brings the message box to the foreground.
  15. Drag a Message Box activity below the previous Message Box activity.

    • In the Properties panel, select the Ok option from the Buttons drop-down list.
    • Add the value "This activity doesn't need to open Word to interact with it. Thank you and goodbye!" in the Text field.
    • Select the check box for the TopMost option. This always brings the message box to the foreground.
    • This is how your workflow should look:



  16. Run the process. Several message boxes display the original text of the document, the text with the added paragraph, and the text with the replaced word.

Was this page helpful?

Get The Help You Need
Learning RPA - Automation Courses
UiPath Community Forum
Uipath Logo White
Trust and Security
© 2005-2024 UiPath. All rights reserved.