View Single Post
  #18   Report Post  
Posted to microsoft.public.word.newusers
Greg Maxey Greg Maxey is offline
external usenet poster
 
Posts: 264
Default Macro for highlighting

On Feb 21, 12:35 pm, Lene Fredborg
wrote:
Anthony,

You only need to combine the two lines of code as in the macro below:

Sub HighLight_Red()
Options.DefaultHighlightColorIndex = wdRed
Selection.Range.HighlightColorIndex = wdRed
End Sub

The first code line changes the highlight button to red.
The second line will apply red highlight to the selection. If no text is
selected, the second line does not make any changes to the text.

--
Regards
Lene Fredborg
DocTools - Denmarkwww.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word



"Anthony Giorgianni" wrote:
Thanks Tony


You're right. I did not understand that difference between the two lines.
But I'm still not certain.


What then would be the sequence to create a taskbar button (say a red box,
for example) that, when clicked, would


1) Change the highlight button to red
2) Turn on red highlighting so that:
a) Highlighted text would turn red or
b) if no text is highlighted, simply turn on red highlighting so
that I can highlight as I read by dragging my cursor across unhighlighted
text?


Right now I'm using:


1) Options.DefaultHighlightColorIndex = wdRed (to select red and turn any
selected text to red)
2) SendKeys "{F10}" (to turn on highlighting - where my computer has been
set to use F10 to turn on highlighting).


I think you are right. It would be better not to use the sendkeys command
(especially if I want to move the macro to another computer). But I'm not
sure of the sequence that will avoid using sendkeys.


Sorry if I'm being obtuse. I'm not very familiar with VB.


Thanks.


Regards,
Anthony Giorgianni


For everyone's benefit, please reply to the group.


"Tony Jollans" My forename at my surname dot com wrote in message
...
There are two (VBA) statements that you seem to be confusing or
misunderstanding:


1. Selection.Range.HighlightColorIndex = wdRed


This highlights the selection without affecting the toolbar button - and
is the one to use to avoid sendkeys.


2. Options.DefaultHighlightColorIndex = wdRed


This changes the toolbar button (which then allows the sendkeys to use it
to get the chosen colour) but does not affect the text.


--
Enjoy,
Tony- Hide quoted text -


- Show quoted text -


Lene,

I think he wanted to change in previous highlighting to red as well.
Also (this could be due to my ToolsOptionsEdit settings) if the IP
is withing a word, even if that word is not selected, it would be
highlighted.

Try:

Sub Scratchmacro()
Dim oRng As Word.Range
Set oRng = ActiveDocument.Content
Options.DefaultHighlightColorIndex = wdRed
With oRng.Find
.Highlight = True
While .Execute
oRng.HighlightColorIndex = Options.DefaultHighlightColorIndex
Wend
End With
If Selection.Range.Start Selection.Range.End Then
Selection.Range.HighlightColorIndex = wdRed
End If
End Sub

AFAIK, this is as close to your ideal as you can get with VBA. You
could then use the format painter tool to continue hightlight text.