![]() |
|
#2
|
||||
|
||||
|
There are two obvious ways to speed up your code.
1. Avoid the selection object to reduce the need for screen scrolling 2. Search each phrase (URL) instead of each word since google.com.au is three separate words and it really should be done as a single find/replace Code:
Sub NewWordReplacement2()
Dim sCheckDoc As String
Dim docRef As Document, docCurrent As Document
Dim i As Integer, arrFind() As String, sFind As String
sCheckDoc = "C:\Folder\Textfile.txt"
Set docCurrent = ActiveDocument
Set docRef = Documents.Open(sCheckDoc)
arrFind = Split(docRef.Range.Text, vbCrLf)
docRef.Close
Options.DefaultHighlightColorIndex = wdRed
With docCurrent.Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.Replacement.Font.Bold = True
.Replacement.Highlight = True
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchWholeWord = False
.MatchCase = True
.MatchWildcards = False
For i = LBound(arrFind) To UBound(arrFind)
sFind = Trim(arrFind(i))
If Len(sFind) > 1 Then
.Text = sFind
.Execute Replace:=wdReplaceAll
End If
Next i
End With
End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Find and highlight multiple words in MS Word document
|
AtaLoss | Word VBA | 37 | 09-22-2021 12:04 PM |
Macro To Identify & Highlight Words In MS Word Based Upon A List In Excel File Column
|
abhimanyu | Word VBA | 5 | 03-20-2020 01:33 PM |
| How to find (highlight) two and more words in a list of 75k single words in Word 2010 | Usora | Word | 8 | 05-29-2018 03:34 AM |
| Find and highlight multiple words in MS Word document | qkjack | Word VBA | 7 | 02-21-2018 07:09 PM |
| Macro to highlight repeated words in word file and extract into excel file | aabri | Word VBA | 1 | 06-14-2015 07:20 AM |