i am not familiar to VBA at all. I found a code online that allows me to replace several words at the same time. I found it a year ago, but i can't find it now so can't give credit to the person who wrote it (my point is, it was not i who wrote it).
It works great, but i instead of entering all of the words in StrFind and StrRepl inside VBscript i want to load the words from a text file in containing a list of words and the corresponding replaced word.
This is the code:
Sub MultiReplace()
Dim StrFind As String, StrRepl As String
Dim i As Long
StrFind = "word1, word2, word3"
StrRepl = "hello1, hello2, hello3"
Set RngTxt = Selection.Range
For i = 0 To UBound(Split(StrFind, ","))
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = Split(StrFind, ",")(i)
.Replacement.Text = Split(StrRepl, ",")(i)
.Format = False
.MatchWholeWord = True
.MatchAllWordForms = False
.MatchWildcards = False
.Execute Replace:=wdReplaceAll
End With
Next i
'
End Sub
I want to adjust the lines StrFind = "word1, word2, word3" StrRepl = "hello1, hello2, hello3" so it gets data from the textfile instead, this because i got an error if i have to much word/letters.
This is how a textfile would look: list.txt:
word1 == hello1
word2 == hello2
It dosent need to be a txt file, an excel would work as well (but i want to remain the superfast time of running the script in word).
Thanks for help