Link to home
Start Free TrialLog in
Avatar of reportingdude
reportingdude

asked on

Add VBA to clear text highlight during replace?

Hello,

I am currently developing a template that will automatically replace text on a word document with text on a form.  The document has all items that need to be replaced or edited highlighted.  I am hoping to include in my vba some code that will unhighlight document text as it is replaced with word text.

Code snippet is as follows, so I would need to insert somewhere here I believe, what I have in there now is not getting rid of the highlight after the replace is done but is working to replace document text with form text:

Private Sub cmdCreateLetter_Click()
On Error Resume Next
Dim xCheckCounter As Long
Dim xCheckBoxName As Object
Dim ASOTemplate As Document
Set ASOTemplate = ActiveDocument
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "[STATE CONTRACTING ENTITY]"
        .Replacement.Text = txtState.Text
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
......<snip>
ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of reportingdude
reportingdude

ASKER

Excellent, that worked beautifully.

Thanks!!!
Perfect solution, exactly what I needed.