View Single Post
  #17   Report Post  
Posted to microsoft.public.word.newusers
Lene Fredborg Lene Fredborg is offline
external usenet poster
 
Posts: 1,291
Default Macro for highlighting

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 - Denmark
www.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