Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
Grey Old Man Grey Old Man is offline
external usenet poster
 
Posts: 8
Default Highlight text via macro

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.

  #2   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.



  #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.



  #4   Report Post  
Posted to microsoft.public.word.docmanagement
Grey Old Man Grey Old Man is offline
external usenet poster
 
Posts: 8
Default Highlight text via macro

Thanks. I have made the change but the error message is the same:
Code is now as follows:

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
Dim lngHCI As Long
'Change the path to reflect where you have stored the table document.
sFname = "C:\My Documents\Highlighting Macro.doc"
Set RefDoc = ActiveDocument
Set TableDoc = Documents.Open(sFname)
Set cTable = TableDoc.Tables(1)
RefDoc.Activate
RefDoc.TrackRevisions = True
lngHCI = Options.DefaultHighlightColorIndex
Options.DefaultHighlightColorIndex = wdBrightGreen
For i = 1 To cTable.Rows.Count
Set oFind = cTable.Cell(i, 1).Range
oFind.End = oFind.End - 1
MsgBox (oFind) 'Testing. This (correctly) displays all of the words in
the table!
With Selection
.HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Execute findText:=oFind, _
MatchWholeWord:=True, _
MatchWildcards:=False, _
Highlight:=True, _
Forward:=True, _
Wrap:=wdFindContinue
End With
End With
Next i
TableDoc.Close wdDoNotSaveChanges
Options.DefaultHighlightColorIndex = lngHCI
RefDoc.TrackRevisions = False
End Sub


"Greg Maxey" wrote:

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.



.

  #5   Report Post  
Posted to microsoft.public.word.docmanagement
Grey Old Man Grey Old Man is offline
external usenet poster
 
Posts: 8
Default Highlight text via macro

Thanks. I have made the change but the error message is the same:
Code is now as follows:

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
Dim lngHCI As Long
'Change the path to reflect where you have stored the table document.
sFname = "C:\My Documents\Highlighting Macro.doc"
Set RefDoc = ActiveDocument
Set TableDoc = Documents.Open(sFname)
Set cTable = TableDoc.Tables(1)
RefDoc.Activate
RefDoc.TrackRevisions = True
lngHCI = Options.DefaultHighlightColorIndex
Options.DefaultHighlightColorIndex = wdBrightGreen
For i = 1 To cTable.Rows.Count
Set oFind = cTable.Cell(i, 1).Range
oFind.End = oFind.End - 1
MsgBox (oFind) 'Testing. This (correctly) displays all of the words in
the table!
With Selection
.HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Execute findText:=oFind, _
MatchWholeWord:=True, _
MatchWildcards:=False, _
Highlight:=True, _
Forward:=True, _
Wrap:=wdFindContinue
End With
End With
Next i
TableDoc.Close wdDoNotSaveChanges
Options.DefaultHighlightColorIndex = lngHCI
RefDoc.TrackRevisions = False
End Sub


"Greg Maxey" wrote:

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.



.



  #6   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default Highlight text via macro

Assuming that you want all the words listed to be highlighted in Green :-

Sub Highlighting()
Dim oChanges As Document, oDoc As Document
Dim oTable As Table
Dim oRng As Range
Dim rFindText As Range
Dim i As Long
Dim sFname As String
sFname = "C:\My Documents\Highlighting Macro.doc"
Set oDoc = ActiveDocument
Set oChanges = Documents.Open(sFname)
Set oTable = oChanges.Tables(1)
For i = 1 To oTable.Rows.Count
Set oRng = oDoc.Range
Set rFindText = oTable.Cell(i, 1).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
Next i
oChanges.Close wdDoNotSaveChanges
End Sub

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org





"Grey Old Man" wrote in message
...
Thanks. I have made the change but the error message is the same:
Code is now as follows:

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
Dim lngHCI As Long
'Change the path to reflect where you have stored the table document.
sFname = "C:\My Documents\Highlighting Macro.doc"
Set RefDoc = ActiveDocument
Set TableDoc = Documents.Open(sFname)
Set cTable = TableDoc.Tables(1)
RefDoc.Activate
RefDoc.TrackRevisions = True
lngHCI = Options.DefaultHighlightColorIndex
Options.DefaultHighlightColorIndex = wdBrightGreen
For i = 1 To cTable.Rows.Count
Set oFind = cTable.Cell(i, 1).Range
oFind.End = oFind.End - 1
MsgBox (oFind) 'Testing. This (correctly) displays all of the words in
the table!
With Selection
.HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Execute findText:=oFind, _
MatchWholeWord:=True, _
MatchWildcards:=False, _
Highlight:=True, _
Forward:=True, _
Wrap:=wdFindContinue
End With
End With
Next i
TableDoc.Close wdDoNotSaveChanges
Options.DefaultHighlightColorIndex = lngHCI
RefDoc.TrackRevisions = False
End Sub


"Greg Maxey" wrote:

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.



.



  #7   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default Highlight text via macro


Assuming that you want all the words listed to be highlighted in Green :-

Sub Highlighting()
Dim oChanges As Document, oDoc As Document
Dim oTable As Table
Dim oRng As Range
Dim rFindText As Range
Dim i As Long
Dim sFname As String
sFname = "C:\My Documents\Highlighting Macro.doc"
Set oDoc = ActiveDocument
Set oChanges = Documents.Open(sFname)
Set oTable = oChanges.Tables(1)
For i = 1 To oTable.Rows.Count
Set oRng = oDoc.Range
Set rFindText = oTable.Cell(i, 1).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
Next i
oChanges.Close wdDoNotSaveChanges
End Sub

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org





"Grey Old Man" wrote in message
...
Thanks. I have made the change but the error message is the same:
Code is now as follows:

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
Dim lngHCI As Long
'Change the path to reflect where you have stored the table document.
sFname = "C:\My Documents\Highlighting Macro.doc"
Set RefDoc = ActiveDocument
Set TableDoc = Documents.Open(sFname)
Set cTable = TableDoc.Tables(1)
RefDoc.Activate
RefDoc.TrackRevisions = True
lngHCI = Options.DefaultHighlightColorIndex
Options.DefaultHighlightColorIndex = wdBrightGreen
For i = 1 To cTable.Rows.Count
Set oFind = cTable.Cell(i, 1).Range
oFind.End = oFind.End - 1
MsgBox (oFind) 'Testing. This (correctly) displays all of the words in
the table!
With Selection
.HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Execute findText:=oFind, _
MatchWholeWord:=True, _
MatchWildcards:=False, _
Highlight:=True, _
Forward:=True, _
Wrap:=wdFindContinue
End With
End With
Next i
TableDoc.Close wdDoNotSaveChanges
Options.DefaultHighlightColorIndex = lngHCI
RefDoc.TrackRevisions = False
End Sub


"Greg Maxey" wrote:

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.



.



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Display selected text as white text with black highlight? David Rathert Microsoft Word Help 4 April 29th 07 03:42 AM
How to highlight Text, but only print text not highlight Darren Microsoft Word Help 7 August 28th 06 04:07 AM
How do I highlight text when recording a macro? jmac52 Microsoft Word Help 1 July 24th 06 02:46 PM
Need a easy Macro to highlight form focus jlawson Microsoft Word Help 2 July 24th 06 02:25 PM
Highlight text, then Save As will use text as file name Chuck Bevitt Microsoft Word Help 3 February 16th 06 06:27 PM


All times are GMT +1. The time now is 03:34 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"