Robotic Process Automation (RPA)

Robotic Process Automation (RPA)

Come for answers. Stay for best practices. All we’re missing is you.

 View Only
  • 1.  How to replace/insert text in a word document?

    Posted Fri March 18, 2022 12:26 PM
    I have a word template with placeholders. How do replace these with text variables? Or insert text at specific locations. I find "Assign value to office" but can't figure out how to use it. Seems more likes it's for Excel.

    ------------------------------
    David Fredriksson
    ------------------------------


  • 2.  RE: How to replace/insert text in a word document?

    Posted Mon March 21, 2022 03:18 AM
    Edited by Stefan Stefanov Mon March 21, 2022 03:18 AM
    Hello David,

    Indeed, use the Assign value to office and for location you specify the page, for example 1.




    ------------------------------
    Stefan Stefanov
    ------------------------------



  • 3.  RE: How to replace/insert text in a word document?

    Posted Mon March 21, 2022 03:57 AM
    Ok. But what's a "location"? How do replace "{placeholder}" with "information" for instance?





  • 4.  RE: How to replace/insert text in a word document?

    Posted Mon March 21, 2022 04:05 AM
    Location for Word files stands for the page that you're applying changes to. In my example it was the first one. If it was for the Excel it would be a cell location. And for the logic of replacing - you could use the "Get office text" followed by "Replace text" commands to replace the placeholders with dynamic variables or constants of your own. After that comes the "Assign value to office" to assign the changed text back to the office file. And don't forget to use the "Save office file" before closing the office file to save the changes applied.

    ------------------------------
    Stefan Stefanov
    ------------------------------



  • 5.  RE: How to replace/insert text in a word document?

    Posted Mon March 21, 2022 04:34 AM
    Ok. So you get the text for the whole page, do replacements in the string and then "copy it" back to word.

    But, this looks like it only works when a whole page has the exact same formatting? I have headers and tables etc.

    ------------------------------
    David Fredriksson
    ------------------------------



  • 6.  RE: How to replace/insert text in a word document?

    Posted Mon March 21, 2022 04:49 AM
    Yes, that's exactly it, but indeed, it only works with same formatting. Perhaps in your case using a macro is the only way to preserve the formatting that I can think of.

    ------------------------------
    Stefan Stefanov
    ------------------------------



  • 7.  RE: How to replace/insert text in a word document?

    Posted Mon March 21, 2022 04:51 AM
    Yes, me too. Thanks anyway for helping out!





  • 8.  RE: How to replace/insert text in a word document?

    Posted Mon March 21, 2022 05:18 AM
    Sure!

    ------------------------------
    Stefan Stefanov
    ------------------------------