Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Closed Thread
 
Thread Tools Display Modes
  #1  
Old 03-20-2020, 04:39 AM
macropod's Avatar
macropod macropod is offline Macro To Identify & Highlight Words In MS Word Based Upon A List In Excel File Column Windows 7 64bit Macro To Identify & Highlight Words In MS Word Based Upon A List In Excel File Column Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,514
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default


Try, for example:
Code:
Sub BulkHighlighter()
Application.ScreenUpdating = False
Dim xlApp As Object, xlWkBk As Object, StrWkBkNm As String
Dim iDataRow As Long, xlList As String, h As Long, i As Long
StrWkBkNm = "C:\Users\" & Environ("Username") & "\Documents\WordList.xlsx"
If Dir(StrWkBkNm) = "" Then
  MsgBox "Cannot find the designated workbook: " & StrWkBkNm, vbExclamation
  Exit Sub
End If
On Error Resume Next
'Start Excel
Set xlApp = CreateObject("Excel.Application")
If xlApp Is Nothing Then
  MsgBox "Can't start Excel.", vbExclamation
  Exit Sub
End If
On Error GoTo 0
With xlApp
  'Hide our Excel session
  .Visible = False
  ' The file is available, so open it.
  Set xlWkBk = .Workbooks.Open(StrWkBkNm, False, True)
  If xlWkBk Is Nothing Then
    MsgBox "Cannot open:" & vbCr & StrWkBkNm, vbExclamation
    .Quit: Set xlApp = Nothing: Exit Sub
  End If
  ' Process the workbook.
  With xlWkBk
    With .Worksheets("Sheet1")
      ' Find the last-used row in column A.
      iDataRow = .Cells(.Rows.Count, 1).End(-4162).Row ' -4162 = xlUp
      ' Capture the F/R data.
      For i = 1 To iDataRow
        ' Skip over empty fields to preserve the underlying cell contents.
        If Trim(.Range("A" & i)) <> vbNullString Then
          xlList = xlList & "|" & Trim(.Range("A" & i))
        End If
      Next
    End With
  .Close False
  End With
  .Quit
End With
' Release Excel object memory
Set xlWkBk = Nothing: Set xlApp = Nothing
'Exit if there are no data
If xlList = "" Then Exit Sub
h = Options.DefaultHighlightColorIndex
Options.DefaultHighlightColorIndex = wdBrightGreen
With ActiveDocument.Range.Find
  .ClearFormatting
  .Replacement.ClearFormatting
  .MatchWholeWord = True
  .MatchCase = True
  .Wrap = wdFindContinue
  .Replacement.Text = "^&"
  .Replacement.Highlight = True
  'Process each word from the List
  For i = 1 To UBound(Split(xlList, "|"))
    .Text = Split(xlList, "|")(i)
    .Execute Replace:=wdReplaceAll
  Next
End With
Options.DefaultHighlightColorIndex = h
Application.ScreenUpdating = True
End Sub
The macro assumes you're using an Excel workbook named 'WordList' stored in your 'Documents' folder and the list is in Column A of 'Sheet1'.
For PC macro installation & usage instructions, see: Installing Macros
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
  #2  
Old 03-20-2020, 09:08 AM
abhimanyu abhimanyu is offline Macro To Identify &amp; Highlight Words In MS Word Based Upon A List In Excel File Column Mac OS X Macro To Identify &amp; Highlight Words In MS Word Based Upon A List In Excel File Column Office 2016 for Mac
Novice
Macro To Identify &amp; Highlight Words In MS Word Based Upon A List In Excel File Column
 
Join Date: Mar 2020
Posts: 3
abhimanyu is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
Try, for example:
...
The macro assumes you're using an Excel workbook named 'WordList' stored in your 'Documents' folder and the list is in Column A of 'Sheet1'.
For PC macro installation & usage instructions, see: Installing Macros


Thanks a lot Paul. Let me check this out.
Closed Thread

Tags
editing a document, macros



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro To Identify &amp; Highlight Words In MS Word Based Upon A List In Excel File Column Highlight words from a list Nanaia Word VBA 3 09-07-2018 02:13 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
Macro To Identify &amp; Highlight Words In MS Word Based Upon A List In Excel File Column Macro to highlight a list of words bakerkr Word VBA 4 10-19-2017 02:23 PM
Macro to highlight repeated words in word file and extract into excel file aabri Word VBA 1 06-14-2015 07:20 AM
Macro To Identify &amp; Highlight Words In MS Word Based Upon A List In Excel File Column Highlight Words from a Word List JSC6 Word VBA 1 09-30-2014 08:22 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:40 AM.


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