View Single Post
  #3   Report Post  
Posted to microsoft.public.word.docmanagement
Greg Maxey[_2_] Greg Maxey[_2_] is offline
external usenet poster
 
Posts: 668
Default Highlight text via macro

That is because "HighlightColorIndex" is not an argument. "Highlight" is an
arguement that you can set to true, false or undefined.

When set to true it will hightlight with the applications current highlight
color. If brightgreen is not the current color then you could do something
like this:

Sub Highlighting()
Dim lngHCI As Long
lngHCI = Options.DefaultHighlightColorIndex
Options.DefaultHighlightColorIndex = wdBrightGreen
'Your corrected code here.
Options.DefaultHighlightColorIndex = lngHCI
End Sub


Grey Old Man wrote:
I am a novice writing a Word macro where I wish to highlight a
selection of words in a document. These pre-defined words are listed
in a table in a second Word document.

I have taken and attempted to modify my macro from an earlier posting
on this forum.

It fails with the message "Named argument not found" on the statement
'HighlightColorIndex:=wdBrightGreen'.

The code is:

Sub Highlighting()
Dim TableDoc As Document ' The document that contains the table
Dim RefDoc As Document ' The document that is being referenced
(highlighted) Dim cTable As Table
Dim oFind As Range
Dim i As Long
Dim sFname As String
'Change the path to reflect where you have stored the table document.
sFname = "C:\My Documents\Testing\Highlighting Macro.doc"
Set RefDoc = ActiveDocument
Set TableDoc = Documents.Open(sFname)
Set cTable = TableDoc.Tables(1)
RefDoc.Activate
RefDoc.TrackRevisions = True
For i = 1 To cTable.Rows.Count
Set oFind = cTable.Cell(i, 1).Range
oFind.End = oFind.End - 1
With Selection
.HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Execute findText:=oFind, _
MatchWholeWord:=True, _
MatchWildcards:=False, _
HighlightColorIndex:=wdBrightGreen, _
Forward:=True, _
Wrap:=wdFindContinue
End With
End With
Next i
TableDoc.Close wdDoNotSaveChanges
RefDoc.TrackRevisions = False
End Sub

Any help would be appreciated.
Thanks in anticipation.