Hi i have a word dcoument which is restricted, with some regions for editing.
But i tried the below invoke to find the editable fields to replace the text, and it doesnt seems to replace.
Originally using the 2nd code for replace, but it doesnt work at all.
For Each storyRange As Microsoft.Office.Interop.Word.Range In odoc.StoryRanges
Console.writeline(storyRange.Editors.Count.toSTRing)
If storyRange.Editors.Count > 0 Then
With storyRange.Find
.Text = “clientName”
.Replacement.Text = dict.ToString
.Forward = True
.Wrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue
.Execute(Replace:=Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll)
End With
End If
Next
Might be the text is inside a protected region and the find execute cannot modify locked content, so you need to directly access the editable ranges such as content controls or bookmarks and set their range text instead of relying on a global find replace.
Using Word Application Scope, open your Word file, Then Inside the scope, add Replace Text activity.
Set Find Text = “clientName”
Set Replace With = “your value”
If its find text in mutiple places, you have option to replace all as well, just enable toggle button if required.