'Macro Multiple find and replace (over 500) in Word Docx
Just wanted to say people who can code are seriously next level, I am unfortunately not one of those people. I'v been set a task at work, which I assume there must be a quicker way to complete.
After research I came across this, but it only works for 15 words at a time, but I have around 500 words to find and replace, which I had been doing manually.
Any adaptations, if you dont mind, please dumb it down for me, all I know is how to paste to Visual Basic and run. I can input comma separated values/paths.
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 comma: ", "Items to be found")
strReplaceText = InputBox("Enter new items here, seperated by comma: ", "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 With
Next nSplitItem
Application.ScreenUpdating = True
End Sub
Any help would be very appreciated : )
Bonus Question: How to apply all these find and replacements to 900 documents?
Example data: (Controlled documents so I cant share real data unfortunately)
A dfe-tbh,scf-b9jt,dvf-hnk,pol-jbv,dn-fgm,gh-jkl
B df12-hbt,dvf-dgf,hj-gngk,dbs-ghdn,fbh-ghg,gfn-dhn
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|