Hello,
I am developing VBA code that has two steps:
- Step 1) Import Excel data into a Word document. This section of code works perfectly.
- Step 2) Reformat all words of structure: "ID-??". (Note that here, "?" is the Wildcard that Word uses to represent 'Any Character'. The words have five characters, including a prefix of "ID-".)
I do not yet have working code that does Step 2 in the newly created Word document. Specifically, I want the VBA code to find and reformat all 5-character words with prefix "ID-". Below is the latest iteration of this section of code .
- In other words, I can manually complete the desired reformatting with a Wildcard search in Word of: "ID-??" A Macro recorded when manually doing the formatting within Word is at the bottom of this message.
VBA code segment intended to reformat all five character words of "ID-??".
----------------------------------------------
Recorded Macro:
Thank you for any insight you can please share.
Sven
I am developing VBA code that has two steps:
- Step 1) Import Excel data into a Word document. This section of code works perfectly.
- Step 2) Reformat all words of structure: "ID-??". (Note that here, "?" is the Wildcard that Word uses to represent 'Any Character'. The words have five characters, including a prefix of "ID-".)
I do not yet have working code that does Step 2 in the newly created Word document. Specifically, I want the VBA code to find and reformat all 5-character words with prefix "ID-". Below is the latest iteration of this section of code .
- In other words, I can manually complete the desired reformatting with a Wildcard search in Word of: "ID-??" A Macro recorded when manually doing the formatting within Word is at the bottom of this message.
VBA code segment intended to reformat all five character words of "ID-??".
VBA Code:
With myDoc.Range.Find
.ClearFormatting
With .Replacement
.ClearFormatting
.Text = "ID-??"
With .Font
.Bold = True
.Color = RGB(200, 200, 0)
End With
End With
.Format = True
.Forward = True
.MatchWildcards = True
End With
Recorded Macro:
VBA Code:
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Font.Color = -671039489
With Selection.Find
.Text = "ID-??"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Thank you for any insight you can please share.
Sven