Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 01-18-2023, 06:10 PM
Big_Sugah Big_Sugah is offline Highlight word document with words from .txt file Windows 10 Highlight word document with words from .txt file Office 2016
Novice
Highlight word document with words from .txt file
 
Join Date: Jan 2023
Posts: 5
Big_Sugah is on a distinguished road
Default Highlight word document with words from .txt file


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
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Highlight word document with words from .txt file Find and highlight multiple words in MS Word document AtaLoss Word VBA 37 09-22-2021 12:04 PM
Highlight word document with words from .txt file 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

Other Forums: Access Forums

All times are GMT -7. The time now is 01:00 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft