# Word automation

**URL:** <https://forum.robotframework.org/t/word-automation/6606>\
**Category:** Robot Framework\
**Created:** [4 January 2024 10:39 UTC](https://forum.robotframework.org/t/word-automation/6606 "2024-01-04T10:39:34Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pjos\_5.272022](https://avatars.discourse-cdn.com/v4/letter/p/49beb7/32.png) [@Pjos\_5.272022](https://forum.robotframework.org/u/Pjos_5.272022)\
**Post date:** [4 January 2024 10:39 UTC](https://forum.robotframework.org/t/word-automation/6606/1 "2024-01-04T10:39:34Z")

</div>

Hi,

Iam new to Robo corp i need one help.  
I need to replace some text in the word document but values are dynamic.  
Thanks in advance.

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [4 January 2024 11:26 UTC](https://forum.robotframework.org/t/word-automation/6606/2 "2024-01-04T11:26:44Z")

</div>

Hi Prasanth,

> [@Pjos\_5.272022](#):
>
> I need to replace some text in the word document but values are dynamic.

1. Do you mean you need to update a custom document property, like this:  
[How to use a custom document property to repeat content in Microsoft Word | TechRepublic](https://www.techrepublic.com/article/use-custom-property-repeat-word/)

2. Or do you mean that you have value in your word document that you need to find and replace with a dynamic value in your robot script?

The second option is probably easier, it can easily be achieved with [Replace Text](https://robocorp.com/docs/libraries/rpa-framework/rpa-word-application/keywords#replace-text), but with out a clear understanding of what you want to acheive we could easily send you in the wrong direction.

Dave.

---

<div class="post-metadata">

**Author:** ![Pjos\_5.272022](https://avatars.discourse-cdn.com/v4/letter/p/49beb7/32.png) [@Pjos\_5.272022](https://forum.robotframework.org/u/Pjos_5.272022)\
**Post date:** [4 January 2024 12:04 UTC](https://forum.robotframework.org/t/word-automation/6606/3 "2024-01-04T12:04:18Z")

</div>

I need a solution for second option  
i need to replace the value which is dynamic.  
refer the sample file the highlighted value need to replace.

 ![robocorp_word](https://europe1.discourse-cdn.com/flex005/uploads/robotframework1/original/2X/f/febe0f89f3be90997b9ec643aaedc829508635b4.png)

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [4 January 2024 12:25 UTC](https://forum.robotframework.org/t/word-automation/6606/4 "2024-01-04T12:25:43Z")

</div>

Hi Prasanth,

So as I mentioned you just need `Replace Text`, see the link in my previous post.

you will need to do something like:

- `Open File`
- `Replace Text`
- `Save Document` or `Save Document As`
- `Close Document`

Refer to the [example](https://robocorp.com/docs/libraries/rpa-framework/rpa-word-application) and the keyword documentation and you should able to do that.

Dave.

---

<div class="post-metadata">

**Author:** ![TextSolver34761](https://avatars.discourse-cdn.com/v4/letter/t/9de0a6/32.png) [@TextSolver34761](https://forum.robotframework.org/u/TextSolver34761)\
**Post date:** [4 January 2024 13:18 UTC](https://forum.robotframework.org/t/word-automation/6606/5 "2024-01-04T13:18:15Z")

</div>

Hello

I haven’t got the issue.

> I need to replace some text in the word document but values are dynamic.

Have you tried the Words Lib :

[https://rpaframework.org/libraries/word\_application/](https://rpaframework.org/libraries/word_application/)

It has a get All text Key word and an API 🙂  
[https://rpaframework.org/libraries/word\_application/python.html](https://rpaframework.org/libraries/word_application/python.html)

You might wanna take a look at this method : it replace text in active document

replace\_text(_find: str_, _replace: str_ ) → None

Hope that helps,

Regards,  
TextSolver34761.

---

<div class="post-metadata">

**Author:** ![TextSolver34761](https://avatars.discourse-cdn.com/v4/letter/t/9de0a6/32.png) [@TextSolver34761](https://forum.robotframework.org/u/TextSolver34761)\
**Post date:** [4 January 2024 13:20 UTC](https://forum.robotframework.org/t/word-automation/6606/6 "2024-01-04T13:20:42Z")

</div>

Sorry @damies13 , I didn’t saw your answer.

---

<div class="post-metadata">

**Author:** ![Pjos\_5.272022](https://avatars.discourse-cdn.com/v4/letter/p/49beb7/32.png) [@Pjos\_5.272022](https://forum.robotframework.org/u/Pjos_5.272022)\
**Post date:** [5 January 2024 04:27 UTC](https://forum.robotframework.org/t/word-automation/6606/7 "2024-01-05T04:27:52Z")

</div>

in replace text how can i mention the dynamic value that need to be replaced with some other values

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [5 January 2024 05:09 UTC](https://forum.robotframework.org/t/word-automation/6606/8 "2024-01-05T05:09:17Z")

</div>

Hi Prasanth,

For example you want to replace the second item highlighted in blue you would do something like:

```python
    Replace Text $390.00 ${your_dynamic_variable}

```

Ideally you’d want to control the original “template” document used by the test, to put a unique value in each location that needs to be replaced to make your test cases easier.

Dave.

---

<div class="post-metadata">

**Author:** ![Pjos\_5.272022](https://avatars.discourse-cdn.com/v4/letter/p/49beb7/32.png) [@Pjos\_5.272022](https://forum.robotframework.org/u/Pjos_5.272022)\
**Post date:** [5 January 2024 05:13 UTC](https://forum.robotframework.org/t/word-automation/6606/9 "2024-01-05T05:13:54Z")

</div>

Here $390.00 not fixed its also dynamic

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [5 January 2024 05:34 UTC](https://forum.robotframework.org/t/word-automation/6606/10 "2024-01-05T05:34:36Z")

</div>

In that case the RPA libraries are not going to be enough as they seem quite limited in what they can do with a word document.

I don’t know of a robot framework library that will do what you need with a word document.

There is the [python-docx](https://python-docx.readthedocs.io/en/latest/) module that can probably do what you need, but you will need to be able to code it in python.

I expect what you’d want to do is:

- open the document
- find all tables
- iterate over each table and check cells in each table to identify you have the one you want
- address the cell by row/column number
  - read the current value if you need to
  - replace cell contents with new value

- save and close document

I’ll suggest trying to make generic python keywords for robot framework that you can reuse, e.g.

- A `Get Tables` keyword that returns a list of tables objects
- A `Get Cell Value` that takes a tables object, row number and column number and returns the value of the cell
- A `Set Cell Value` that takes a tables object, row number, column number, and new value, that updates the cell

Unfortunately unless someone else knows of a robot framework library that can edit word documents at this level, you’ve got some coding ahead of you.

Dave.

---

<div class="post-metadata">

**Author:** ![Pjos\_5.272022](https://avatars.discourse-cdn.com/v4/letter/p/49beb7/32.png) [@Pjos\_5.272022](https://forum.robotframework.org/u/Pjos_5.272022)\
**Post date:** [5 January 2024 06:07 UTC](https://forum.robotframework.org/t/word-automation/6606/11 "2024-01-05T06:07:18Z")

</div>

Thanks for your help.
