cancel
Showing results for 
Search instead for 
Did you mean: 

how to find and replace text in word document ?

SameerJoshi
Level 4
I need to open the word document and then need to find and replace some text. Created a process and used MS Word VBO and created stages as below. 1. Open the document (works fine) 2. Show the document (works fine) 3. Find the text (it finds the text and highlights the same) 4. Replace the highlighted text ( didn't work ) Tried to set values 0, 1 as current highlight and new highlight parameter but then also did not worked. Also tried to call Get Highlighted Text method before replacing but observed that output collection was empty. Any suggestion on what I am missing will be helpful
4 REPLIES 4

david.l.morris
Level 14
Hi Sameer, Same issue here. Just adding to the conversation...(and also to confirm that others are also having this issue) I tested your scenario in the MS Word VBO, and I had the same result as you. The ""Find Text"" action works, and then the ""Replace Highlighted Text"" action runs with no errors but the replacement does not occur in the document. I sat down with a colleague to look at the code in that action of the MS Word VBO. I don't know the cause of the issue. However, this part of the code returns false, because it doesn't find the text you're looking for: Do While r.Find.Execute(current_text) Maybe a fix can be included in a new version of MS Word VBO or in a future release of BP if the issue isn't coming from the VBO. Respectfully, Dave
Dave Morris 3Ci at Southern Company Atlanta, GA

BartPepels
Level 2
What works is first deleting the selected text and then use the action type text. For me it works fine. Btw the safest option is to put the text applicable for change between . So if you are able to work with a Word template adopt it in a way that you search for .

BartPepels
Level 2
VB code (input handle (number) and documentname (text) : ""GetInstance(handle).Selection.Delete()

Yes type text worked for me as well, but was trying to leverage existing method, thanks for all comments!!