Hi Everyone,
I would like help in a script I have. This script is meant to highlight words based off a local .txt file. The word document I use has anywhere between 100-300 pages
I find the following script appears to not highlight the entire word and takes a long time to execute.
An example of the .txt document would be
Quote:
Google.com
Google.com.au
Facebook.com
Yahoo.com
|
etc
Is there any improvements to this script that can be performed? For increased running time and how it actually works
Code:
Sub NewWordReplacement1()
Dim sCheckDoc As String
Dim docRef As Document
Dim docCurrent As Document
Dim wrdRef As Object
sCheckDoc = "C:\Folder\Textfile.txt"
Set docCurrent = Selection.Document
Set docRef = Documents.Open(sCheckDoc)
docCurrent.Activate
Options.DefaultHighlightColorIndex = wdRed
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Replacement.Font.Bold = True
.Forward = True
.Format = True
.MatchWholeWord = True
.MatchCase = True
.MatchWildcards = False
End With
For Each wrdRef In docRef.Words
If Asc(Left(wrdRef, 1)) > 32 Then
With Selection.Find
.Wrap = wdFindContinue
.Text = wrdRef
.Execute Replace:=wdReplaceAll
.Replacement.Highlight = True
End With
End If
Next wrdRef
docRef.Close
docCurrent.Activate
End Sub