![]() |
#1
|
|||
|
|||
![]() 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:
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 |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
AtaLoss | Word VBA | 37 | 09-22-2021 12:04 PM |
![]() |
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 |