G
Guest
Anthony,
I know that your can use your current macros but, anyway, I will try to
explain a little more ;-) - not least because it could make your work even
easier.
After your latest explanation I am sure that what both Tony and I started to
explain is the only thing you need - a single line of code in the macro (no
SendKeys) - and you can have a macro for each highlight color. The only
passage in your explanation that confuses me a little is "(usually without
selecting it first)" - I think you select the text you want to highlight
or?...
I (and a lot of people I have created macros for) do what you do several
times every day, i.e. apply different highlight colors to text and for that
purpose I have created a series of macros like the ones below - one per used
color. In order to make it fast and easy to apply the different colors, I
have assigned shortcuts to the individual highlight macros (they have been
added to a custom toolbar as well - with colored icons as you describe). I
have used these shortcuts that do not conflict with built-in shortcuts and
that are easy to remember:
Alt+Ctrl+Y for Yellow (wdYellow)
Alt+Ctrl+P for Pink (wdPink)
Alt+Ctrl+G for Green (wdBrightGreen)
Alt+Ctrl+B for Blue (wdTurquoise)
Alt+Ctrl+R for Red (wdRed)
Alt+Ctrl+< for no highlight (wdNoHighlight) - i.e. the macro that removes
the highlight
The _important_ thing is that when you apply the highlight via a _macro_,
you can do that _without_ first changing the highlight color of the highlight
icon. You simply do not need "Selection.Range.HighlightColorIndex = wdRed". I
know that this line is the only one you get if you record a macro but, as
Tony said, the macro recorder is not perfect - that macro does not apply any
highlight when executed afterwards. For that purpose you need
"Selection.Range.HighlightColorIndex = [your color]".
So back to the start:
The following macro will change the highlight color of the selection to red
_regardless_ of what color is currently shown in the highlight icon (i.e. the
macro determines the color, not the highlight icon):
Sub HighLight_Red()
Selection.Range.HighlightColorIndex = wdRed
End Sub
Correspondingly, the following macro will change the highlight color of the
selection to yellow _regardless_ of what color is currently shown in the
highlight icon:
Sub HighLight_Yellow()
Selection.Range.HighlightColorIndex = wdYellow
End Sub
The following macro will _remove_ any highlight from the selection
_regardless_ of what color is currently shown in the highlight icon:
Sub HighLight_Red()
Selection.Range.HighlightColorIndex = wdNoHighlight
End Sub
This way you can create a corresponding macro for each of the highlight
colors you want to use. And if you assign shortcuts, you can apply any of the
highlight colors or remove the highlight simply by pressing the shortcut
(that is what I always do). You never need to care about which color is
selected in the highlight icon.
Hope this helps.
--
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
I know that your can use your current macros but, anyway, I will try to
explain a little more ;-) - not least because it could make your work even
easier.
After your latest explanation I am sure that what both Tony and I started to
explain is the only thing you need - a single line of code in the macro (no
SendKeys) - and you can have a macro for each highlight color. The only
passage in your explanation that confuses me a little is "(usually without
selecting it first)" - I think you select the text you want to highlight
or?...
I (and a lot of people I have created macros for) do what you do several
times every day, i.e. apply different highlight colors to text and for that
purpose I have created a series of macros like the ones below - one per used
color. In order to make it fast and easy to apply the different colors, I
have assigned shortcuts to the individual highlight macros (they have been
added to a custom toolbar as well - with colored icons as you describe). I
have used these shortcuts that do not conflict with built-in shortcuts and
that are easy to remember:
Alt+Ctrl+Y for Yellow (wdYellow)
Alt+Ctrl+P for Pink (wdPink)
Alt+Ctrl+G for Green (wdBrightGreen)
Alt+Ctrl+B for Blue (wdTurquoise)
Alt+Ctrl+R for Red (wdRed)
Alt+Ctrl+< for no highlight (wdNoHighlight) - i.e. the macro that removes
the highlight
The _important_ thing is that when you apply the highlight via a _macro_,
you can do that _without_ first changing the highlight color of the highlight
icon. You simply do not need "Selection.Range.HighlightColorIndex = wdRed". I
know that this line is the only one you get if you record a macro but, as
Tony said, the macro recorder is not perfect - that macro does not apply any
highlight when executed afterwards. For that purpose you need
"Selection.Range.HighlightColorIndex = [your color]".
So back to the start:
The following macro will change the highlight color of the selection to red
_regardless_ of what color is currently shown in the highlight icon (i.e. the
macro determines the color, not the highlight icon):
Sub HighLight_Red()
Selection.Range.HighlightColorIndex = wdRed
End Sub
Correspondingly, the following macro will change the highlight color of the
selection to yellow _regardless_ of what color is currently shown in the
highlight icon:
Sub HighLight_Yellow()
Selection.Range.HighlightColorIndex = wdYellow
End Sub
The following macro will _remove_ any highlight from the selection
_regardless_ of what color is currently shown in the highlight icon:
Sub HighLight_Red()
Selection.Range.HighlightColorIndex = wdNoHighlight
End Sub
This way you can create a corresponding macro for each of the highlight
colors you want to use. And if you assign shortcuts, you can apply any of the
highlight colors or remove the highlight simply by pressing the shortcut
(that is what I always do). You never need to care about which color is
selected in the highlight icon.
Hope this helps.
--
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word