Worb VBA multiple find and replace at once - Not getting Bold text in output

PRAKASH SUBBURAM 1 Reputation point
2022-07-09T00:47:05.047+00:00

Hi
Below Word vba code is working good But the issue is i did not get bold text after replacement. Please help me

Sub PROSECLOCATIONS()
Dim strFind As String, strReplace As String
Dim strFindArr, strReplaceArr
Dim I As Long
strFind = "INBLOCK,ESTS20FT,MCC05,UDDS,UDDN,UDDN05,VEGYARD,COUYARD,DEBOER,CCC,UDD01G2,GISLAND,DOLLY,PAXQRT,PAX QRT,UNMANIFESTED ULD,UNMANIFESTEDULD,AVIFACILITY"
strReplace = "INBLOCK,ESTS-20FT,MCC-05,UDD-S,UDD-N,UDD-N05,VEG YARD,COU YARD,DEBOER,CCC,UDD01G2,GISLAND,DOLLY,PAX QRT,PAX QRT,UNMANIFESTED ULD,UNMANIFESTED ULD,AVI FACILITY"
strFindArr = Split(strFind, ",")
strReplaceArr = Split(strReplace, ",")
For I = 0 To UBound(strFindArr)
Selection.HomeKey Unit:=wdStory, Extend:=wdMove
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = strFindArr(I)
.Replacement.Text = strReplaceArr(I)
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Font.Bold = True
Next
End Sub

0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Viorel 119.6K Reputation points
    2022-07-09T05:58:55.25+00:00

    Try placing the line Selection.Find.Replacement.Font.Bold = True before Selection.Find.Execute Replace:=wdReplaceAll.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.