J
John Svendsen
Hi All,
I've put together VBA code that will find and replace text string pairs from
a file (see code below). However, all find and replace text strings end up
with the same format as the first character of the find string.
Is there a way I can introduce different formatting in this (e.g., find
string "aaa bbb ccc" [where bbb is bold/underscore/etc] and replace with
string "111 222 333 444" [where 333 is bold/underscore/etc]) in this macro?
Or, doe anyone have a better idea?
Thank you very much for your attention and time.
Rgds, JS
Sub po2en()
Dim sFirst, sLast As String
Open "c:\po2en.txt" For Input As #1
Do While Not EOF(1)
Input #1, sFirst, sLast
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = sFirst
.Replacement.Text = sLast
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Loop
Close #1
End Sub
I've put together VBA code that will find and replace text string pairs from
a file (see code below). However, all find and replace text strings end up
with the same format as the first character of the find string.
Is there a way I can introduce different formatting in this (e.g., find
string "aaa bbb ccc" [where bbb is bold/underscore/etc] and replace with
string "111 222 333 444" [where 333 is bold/underscore/etc]) in this macro?
Or, doe anyone have a better idea?
Thank you very much for your attention and time.
Rgds, JS
Sub po2en()
Dim sFirst, sLast As String
Open "c:\po2en.txt" For Input As #1
Do While Not EOF(1)
Input #1, sFirst, sLast
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = sFirst
.Replacement.Text = sLast
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Loop
Close #1
End Sub