Main Area and Open Discussion > General Software Discussion
Multiple Find and replace in a word file
Contro:
Microsoft word have a find and replace option to search for a string and replace with another one.
But I need to search for several strings and replace each of them by a replacement one. So i need a multiple find and replace .
Do you know an utility to do this ?
Best Regards
Contro:
4wd ;D
this seems go well for me :
https://www.datanumen.com/blogs/find-replace-multiple-items-word-document/
Contro:
Can I change the delimiters ?
The script tells to seperate the strings with "," .
Can I use other delimiter ? Sometimess the string itself contain a comma....
:-[
Note : I think I can try to modify the delimiters by try and result.
4wd:
--- Code: Visual Basic ---Sub FindAndReplaceMultiItems() Dim strFindText As String Dim strReplaceText As String Dim nSplitItem As Long Application.ScreenUpdating = False ' Enter items to be replaces and new ones. strFindText = InputBox("Enter items to be found here,seperated by | (vertical bar): ", "Items to be found") strReplaceText = InputBox("Enter new items here, seperated by | (vertical bar): ", "New items") nSplitItem = UBound(Split(strFindText, "|")) ' Find each item and replace it with new one respectively. For nSplitItem = 0 To nSplitItem With Selection .HomeKey Unit:=wdStory With Selection.Find .ClearFormatting .Replacement.ClearFormatting .Text = Split(strFindText, "|")(nSplitItem) .Replacement.Text = Split(strReplaceText, "|")(nSplitItem) .Format = False .MatchWholeWord = False End With Selection.Find.Execute Replace:=wdReplaceAll End WithNext nSplitItem Application.ScreenUpdating = True End Sub
Try that, it uses | instead. (Not tested since I'm on a tablet.)
Contro:
--- Code: Visual Basic ---Sub FindAndReplaceMultiItems() Dim strFindText As String Dim strReplaceText As String Dim nSplitItem As Long Application.ScreenUpdating = False ' Enter items to be replaces and new ones. strFindText = InputBox("Enter items to be found here,seperated by | (vertical bar): ", "Items to be found") strReplaceText = InputBox("Enter new items here, seperated by | (vertical bar): ", "New items") nSplitItem = UBound(Split(strFindText, "|")) ' Find each item and replace it with new one respectively. For nSplitItem = 0 To nSplitItem With Selection .HomeKey Unit:=wdStory With Selection.Find .ClearFormatting .Replacement.ClearFormatting .Text = Split(strFindText, "|")(nSplitItem) .Replacement.Text = Split(strReplaceText, "|")(nSplitItem) .Format = False .MatchWholeWord = False End With Selection.Find.Execute Replace:=wdReplaceAll End WithNext nSplitItem Application.ScreenUpdating = True End Sub
Try that, it uses | instead. (Not tested since I'm on a tablet.)
-4wd (January 27, 2021, 05:33 PM)
--- End quote ---
4wd i will try and comment
Best Regards
:-* :P
Navigation
[0] Message Index
[#] Next page
Go to full version