![]() |
|
|
|
#1
|
||||
|
||||
|
Create a document with a single column table. Put one of the phrases in each cell (no blanks) save the document then put the name and path in the following macro in place of "C:\Path\Table.docx". Run the macro on your document with the phrases. Code:
Sub Highlighting()
Dim oChanges As Document, oDoc As Document
Dim oTable As Table
Dim oCell As Cell
Dim oRng As Range
Dim rFindText As Range
Const sFname As String = "C:\Path\Table.docx"
Set oDoc = ActiveDocument
Set oChanges = Documents.Open(Filename:=sFname, Visible:=False)
Set oTable = oChanges.Tables(1)
For Each oCell In oTable.Range.Cells
If Len(oCell.Range) > 2 Then
Set oRng = oDoc.Range
Set rFindText = oCell.Range
rFindText.End = rFindText.End - 1
With oRng.Find
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute(FindText:=rFindText, _
MatchWholeWord:=True) = True
oRng.HighlightColorIndex = wdBrightGreen
Loop
End With
End If
Next oCell
lbl_Exit:
oChanges.Close 0
Set oChanges = Nothing
Set oDoc = Nothing
Set oRng = Nothing
Set rFindText = Nothing
Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#2
|
|||
|
|||
|
Thank you so much for your help, can and add the symbols and special charaters also in the tabble??
please help me. |
|
#3
|
|||
|
|||
|
Dear All,
As below code i am able to search for the words existing in the table, but it is not checking as a whole in active document. example: if i keep the abbrevations like "ar" means "as required" and "in" means inch, where as it is highlight all ar letters where ever it is finding, from the word argument it is highlighting ar and in from instructions first two letters, Kindly help me in this regard. Quote:
|
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Search for italicized words
|
ep2002 | Word | 4 | 11-10-2014 10:23 PM |
| Macro to Search for all words with (R) and place in new document | kd12 | Word VBA | 2 | 06-10-2014 02:25 PM |
| How to search for 2 words at the same time | mrayncrental | Word VBA | 1 | 06-08-2014 03:08 AM |
| Multiple words, one search | return2300 | Word VBA | 0 | 08-30-2013 12:26 PM |
Search for words starting in capitals
|
surreytom | Word VBA | 3 | 04-01-2012 01:41 AM |