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.ClearFormat ting
Selection.Find.Replacement .ClearForm atting
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>
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.ClearFormat
Selection.Find.Replacement
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect solution, exactly what I needed.
ASKER
Thanks!!!