Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.newusers
|
|||
|
|||
Macro for highlighting
Hello Everyone
In my old version (2000?) of work I was able to set up macros to turn on highlighting of different colors- having toolbar macros called "Green" "yellow" "red"etc. But I can't seem to do it in word 2003. I've tried importing my old macros and rerecroding as well. It just won't turn on the highlighting. Any ideas? Thanks. Regards, Anthony Giorgianni For everyone's benefit, please reply to the group. |
#2
Posted to microsoft.public.word.newusers
|
|||
|
|||
Macro for highlighting
Can you post an example of a macro that doesn't work?
-- Enjoy, Tony "Anthony Giorgianni" wrote in message ... Hello Everyone In my old version (2000?) of work I was able to set up macros to turn on highlighting of different colors- having toolbar macros called "Green" "yellow" "red"etc. But I can't seem to do it in word 2003. I've tried importing my old macros and rerecroding as well. It just won't turn on the highlighting. Any ideas? Thanks. Regards, Anthony Giorgianni For everyone's benefit, please reply to the group. |
#3
Posted to microsoft.public.word.newusers
|
|||
|
|||
Macro for highlighting
Yes, Tony
Here is what the recorder did when I tried to set it up. Sub Green() ' ' Green Macro ' Macro recorded 1/31/2007 by ' Options.DefaultHighlightColorIndex = wdBrightGreen End Sub It doesn't work to activate green highlighting; nor does it turn selected text green. here is one that definitely ran on office 2000 that doesn't work on Word 2003. It actually brings up "find and replace," oddly, as do all my other old highlighter macros! Sub Red() ' ' Red Macro ' Macro recorded 01/06/2004 by Anthony Giorgianni ' Options.DefaultHighlightColorIndex = wdRed SendKeys "{F5}" End Sub Regards, Anthony Giorgianni For everyone's benefit, please reply to the group. "Tony Jollans" My forename at my surname dot com wrote in message ... Can you post an example of a macro that doesn't work? -- Enjoy, Tony "Anthony Giorgianni" wrote in message ... Hello Everyone In my old version (2000?) of work I was able to set up macros to turn on highlighting of different colors- having toolbar macros called "Green" "yellow" "red"etc. But I can't seem to do it in word 2003. I've tried importing my old macros and rerecroding as well. It just won't turn on the highlighting. Any ideas? Thanks. Regards, Anthony Giorgianni For everyone's benefit, please reply to the group. |
#4
Posted to microsoft.public.word.newusers
|
|||
|
|||
Macro for highlighting
The Macro recorder, unfortunately, is not perfect. All that does is set the
default highlight colour; to apply it to the selection you need: Selection.Range.HighlightColorIndex = wdGreen You don't actually need to set the default colour; the above line is all you need and it will highlight the selcted text in the given colour (green in this example). I don't understand the Find and Replace bit, sorry. -- Enjoy, Tony "Anthony Giorgianni" wrote in message ... Yes, Tony Here is what the recorder did when I tried to set it up. Sub Green() ' ' Green Macro ' Macro recorded 1/31/2007 by ' Options.DefaultHighlightColorIndex = wdBrightGreen End Sub It doesn't work to activate green highlighting; nor does it turn selected text green. here is one that definitely ran on office 2000 that doesn't work on Word 2003. It actually brings up "find and replace," oddly, as do all my other old highlighter macros! Sub Red() ' ' Red Macro ' Macro recorded 01/06/2004 by Anthony Giorgianni ' Options.DefaultHighlightColorIndex = wdRed SendKeys "{F5}" End Sub Regards, Anthony Giorgianni For everyone's benefit, please reply to the group. "Tony Jollans" My forename at my surname dot com wrote in message ... Can you post an example of a macro that doesn't work? -- Enjoy, Tony "Anthony Giorgianni" wrote in message ... Hello Everyone In my old version (2000?) of work I was able to set up macros to turn on highlighting of different colors- having toolbar macros called "Green" "yellow" "red"etc. But I can't seem to do it in word 2003. I've tried importing my old macros and rerecroding as well. It just won't turn on the highlighting. Any ideas? Thanks. Regards, Anthony Giorgianni For everyone's benefit, please reply to the group. |
#5
Posted to microsoft.public.word.newusers
|
|||
|
|||
Macro for highlighting
The following macro will change the highlight color of the selection to red -
it does not change the color selected in the Highlight icon in the Formatting toolbar: Sub HighLight_Red() Selection.Range.HighlightColorIndex = wdRed End Sub If you want to change the color selected in the Highlight icon too, add the following code line to the macro: Options.DefaultHighlightColorIndex = wdRed Replace wdRed by the desired WdColorIndex. -- Regards Lene Fredborg DocTools - Denmark www.thedoctools.com Document automation - add-ins, macros and templates for Microsoft Word "Anthony Giorgianni" wrote: Hello Everyone In my old version (2000?) of work I was able to set up macros to turn on highlighting of different colors- having toolbar macros called "Green" "yellow" "red"etc. But I can't seem to do it in word 2003. I've tried importing my old macros and rerecroding as well. It just won't turn on the highlighting. Any ideas? Thanks. Regards, Anthony Giorgianni For everyone's benefit, please reply to the group. |
#6
Posted to microsoft.public.word.newusers
|
|||
|
|||
Macro for highlighting
I somehow failed to notice that the answer in my post above was already given
by Tony Jollans. Sorry. -- Regards Lene Fredborg DocTools - Denmark www.thedoctools.com Document automation - add-ins, macros and templates for Microsoft Word "Lene Fredborg" wrote: The following macro will change the highlight color of the selection to red - it does not change the color selected in the Highlight icon in the Formatting toolbar: Sub HighLight_Red() Selection.Range.HighlightColorIndex = wdRed End Sub If you want to change the color selected in the Highlight icon too, add the following code line to the macro: Options.DefaultHighlightColorIndex = wdRed Replace wdRed by the desired WdColorIndex. -- Regards Lene Fredborg DocTools - Denmark www.thedoctools.com Document automation - add-ins, macros and templates for Microsoft Word "Anthony Giorgianni" wrote: Hello Everyone In my old version (2000?) of work I was able to set up macros to turn on highlighting of different colors- having toolbar macros called "Green" "yellow" "red"etc. But I can't seem to do it in word 2003. I've tried importing my old macros and rerecroding as well. It just won't turn on the highlighting. Any ideas? Thanks. Regards, Anthony Giorgianni For everyone's benefit, please reply to the group. |
#7
Posted to microsoft.public.word.newusers
|
|||
|
|||
Macro for highlighting
No need to apologise, Lene. At least we both gave the same answer :-)
-- Enjoy, Tony "Lene Fredborg" wrote in message ... I somehow failed to notice that the answer in my post above was already given by Tony Jollans. Sorry. -- Regards Lene Fredborg DocTools - Denmark www.thedoctools.com Document automation - add-ins, macros and templates for Microsoft Word "Lene Fredborg" wrote: The following macro will change the highlight color of the selection to red - it does not change the color selected in the Highlight icon in the Formatting toolbar: Sub HighLight_Red() Selection.Range.HighlightColorIndex = wdRed End Sub If you want to change the color selected in the Highlight icon too, add the following code line to the macro: Options.DefaultHighlightColorIndex = wdRed Replace wdRed by the desired WdColorIndex. -- Regards Lene Fredborg DocTools - Denmark www.thedoctools.com Document automation - add-ins, macros and templates for Microsoft Word "Anthony Giorgianni" wrote: Hello Everyone In my old version (2000?) of work I was able to set up macros to turn on highlighting of different colors- having toolbar macros called "Green" "yellow" "red"etc. But I can't seem to do it in word 2003. I've tried importing my old macros and rerecroding as well. It just won't turn on the highlighting. Any ideas? Thanks. Regards, Anthony Giorgianni For everyone's benefit, please reply to the group. |
#8
Posted to microsoft.public.word.newusers
|
|||
|
|||
Macro for highlighting
Thanks, Tony. Anyway, two similar answers are better than none ;-)
-- Regards Lene Fredborg DocTools - Denmark www.thedoctools.com Document automation - add-ins, macros and templates for Microsoft Word "Tony Jollans" wrote: No need to apologise, Lene. At least we both gave the same answer :-) -- Enjoy, Tony "Lene Fredborg" wrote in message ... I somehow failed to notice that the answer in my post above was already given by Tony Jollans. Sorry. -- Regards Lene Fredborg DocTools - Denmark www.thedoctools.com Document automation - add-ins, macros and templates for Microsoft Word "Lene Fredborg" wrote: The following macro will change the highlight color of the selection to red - it does not change the color selected in the Highlight icon in the Formatting toolbar: Sub HighLight_Red() Selection.Range.HighlightColorIndex = wdRed End Sub If you want to change the color selected in the Highlight icon too, add the following code line to the macro: Options.DefaultHighlightColorIndex = wdRed Replace wdRed by the desired WdColorIndex. -- Regards Lene Fredborg DocTools - Denmark www.thedoctools.com Document automation - add-ins, macros and templates for Microsoft Word "Anthony Giorgianni" wrote: Hello Everyone In my old version (2000?) of work I was able to set up macros to turn on highlighting of different colors- having toolbar macros called "Green" "yellow" "red"etc. But I can't seem to do it in word 2003. I've tried importing my old macros and rerecroding as well. It just won't turn on the highlighting. Any ideas? Thanks. Regards, Anthony Giorgianni For everyone's benefit, please reply to the group. |
#9
Posted to microsoft.public.word.newusers
|
|||
|
|||
Macro for highlighting
Thank you both. Works well. Now to finish it, how do I just turn on
highlighting tool with the appropriate color so that I can go highlighting things without selecting them first? Regards, Anthony Giorgianni For everyone's benefit, please reply to the group. "Tony Jollans" My forename at my surname dot com wrote in message ... The Macro recorder, unfortunately, is not perfect. All that does is set the default highlight colour; to apply it to the selection you need: Selection.Range.HighlightColorIndex = wdGreen You don't actually need to set the default colour; the above line is all you need and it will highlight the selcted text in the given colour (green in this example). I don't understand the Find and Replace bit, sorry. -- Enjoy, Tony "Anthony Giorgianni" wrote in message ... Yes, Tony Here is what the recorder did when I tried to set it up. Sub Green() ' ' Green Macro ' Macro recorded 1/31/2007 by ' Options.DefaultHighlightColorIndex = wdBrightGreen End Sub It doesn't work to activate green highlighting; nor does it turn selected text green. here is one that definitely ran on office 2000 that doesn't work on Word 2003. It actually brings up "find and replace," oddly, as do all my other old highlighter macros! Sub Red() ' ' Red Macro ' Macro recorded 01/06/2004 by Anthony Giorgianni ' Options.DefaultHighlightColorIndex = wdRed SendKeys "{F5}" End Sub Regards, Anthony Giorgianni For everyone's benefit, please reply to the group. "Tony Jollans" My forename at my surname dot com wrote in message ... Can you post an example of a macro that doesn't work? -- Enjoy, Tony "Anthony Giorgianni" wrote in message ... Hello Everyone In my old version (2000?) of work I was able to set up macros to turn on highlighting of different colors- having toolbar macros called "Green" "yellow" "red"etc. But I can't seem to do it in word 2003. I've tried importing my old macros and rerecroding as well. It just won't turn on the highlighting. Any ideas? Thanks. Regards, Anthony Giorgianni For everyone's benefit, please reply to the group. |
#10
Posted to microsoft.public.word.newusers
|
|||
|
|||
Macro for highlighting
Not sure about not selecting them first but the recorded code you posted
should change the default on the toolbar button -- Enjoy, Tony "Anthony Giorgianni" wrote in message ... Thank you both. Works well. Now to finish it, how do I just turn on highlighting tool with the appropriate color so that I can go highlighting things without selecting them first? Regards, Anthony Giorgianni For everyone's benefit, please reply to the group. "Tony Jollans" My forename at my surname dot com wrote in message ... The Macro recorder, unfortunately, is not perfect. All that does is set the default highlight colour; to apply it to the selection you need: Selection.Range.HighlightColorIndex = wdGreen You don't actually need to set the default colour; the above line is all you need and it will highlight the selcted text in the given colour (green in this example). I don't understand the Find and Replace bit, sorry. -- Enjoy, Tony "Anthony Giorgianni" wrote in message ... Yes, Tony Here is what the recorder did when I tried to set it up. Sub Green() ' ' Green Macro ' Macro recorded 1/31/2007 by ' Options.DefaultHighlightColorIndex = wdBrightGreen End Sub It doesn't work to activate green highlighting; nor does it turn selected text green. here is one that definitely ran on office 2000 that doesn't work on Word 2003. It actually brings up "find and replace," oddly, as do all my other old highlighter macros! Sub Red() ' ' Red Macro ' Macro recorded 01/06/2004 by Anthony Giorgianni ' Options.DefaultHighlightColorIndex = wdRed SendKeys "{F5}" End Sub Regards, Anthony Giorgianni For everyone's benefit, please reply to the group. "Tony Jollans" My forename at my surname dot com wrote in message ... Can you post an example of a macro that doesn't work? -- Enjoy, Tony "Anthony Giorgianni" wrote in message ... Hello Everyone In my old version (2000?) of work I was able to set up macros to turn on highlighting of different colors- having toolbar macros called "Green" "yellow" "red"etc. But I can't seem to do it in word 2003. I've tried importing my old macros and rerecroding as well. It just won't turn on the highlighting. Any ideas? Thanks. Regards, Anthony Giorgianni For everyone's benefit, please reply to the group. |
#11
Posted to microsoft.public.word.newusers
|
|||
|
|||
Macro for highlighting
Thanks Tony.
I found the problem. On my old laptop, I must have assigned F5 to turn on hgihlighting. So when I transferred the macro to my new laptop with "Sendkey" F5, it didn't trigger the highlighter but instead ran Find and replace, the assignment for f5 on that machine :O) Now it works fine with: Sub HighLight_Red() Selection.Range.HighlightColorIndex = wdRed SendKeys "(F10)" With F10 now assigned to turn on highlighting. End Sub Thanks again to you and Lene. Regards, Anthony Giorgianni For everyone's benefit, please reply to the group. |
#12
Posted to microsoft.public.word.newusers
|
|||
|
|||
oops - Macro for highlighting
Oooops .... make that
Sub Highlight red() Options.DefaultHighlightColorIndex = wdRed SendKeys "{F10}" End Sub This turns on highlighting to highlight unselected text or highlights selected text. Thanks again. Regards, Anthony Giorgianni For everyone's benefit, please reply to the group. "Anthony Giorgianni" wrote in message ... Thanks Tony. I found the problem. On my old laptop, I must have assigned F5 to turn on hgihlighting. So when I transferred the macro to my new laptop with "Sendkey" F5, it didn't trigger the highlighter but instead ran Find and replace, the assignment for f5 on that machine :O) Now it works fine with: Sub HighLight_Red() Selection.Range.HighlightColorIndex = wdRed SendKeys "(F10)" With F10 now assigned to turn on highlighting. End Sub Thanks again to you and Lene. Regards, Anthony Giorgianni For everyone's benefit, please reply to the group. |
#13
Posted to microsoft.public.word.newusers
|
|||
|
|||
Macro for highlighting
Whilst that may work for you ...
* most people don't have F10 - or any key - assigned to highlighting * Sendkeys is generally best avoided If you use the explicit statement (Selection.Range.HighlightColorIndex = wdRed) that Lene and I have both suggested you will find it works just as well. The only difference (which you'll generally be unaware of) is that it will work when Sendkeys would have failed, and also that it will work for other people as well. -- Enjoy, Tony "Anthony Giorgianni" wrote in message ... Thanks Tony. I found the problem. On my old laptop, I must have assigned F5 to turn on hgihlighting. So when I transferred the macro to my new laptop with "Sendkey" F5, it didn't trigger the highlighter but instead ran Find and replace, the assignment for f5 on that machine :O) Now it works fine with: Sub HighLight_Red() Selection.Range.HighlightColorIndex = wdRed SendKeys "(F10)" With F10 now assigned to turn on highlighting. End Sub Thanks again to you and Lene. Regards, Anthony Giorgianni For everyone's benefit, please reply to the group. |
#14
Posted to microsoft.public.word.newusers
|
|||
|
|||
Macro for highlighting
Thanks Tony
But without using Sendkey, I can't figure out how simply to turn on highlighting without selecting anything first. Am I missing something? -- Regards, Anthony Giorgianni The return address for this post is fictitious. Please reply by posting back to the newsgroup. "Tony Jollans" My forename at my surname dot com wrote in message ... Whilst that may work for you ... * most people don't have F10 - or any key - assigned to highlighting * Sendkeys is generally best avoided If you use the explicit statement (Selection.Range.HighlightColorIndex = wdRed) that Lene and I have both suggested you will find it works just as well. The only difference (which you'll generally be unaware of) is that it will work when Sendkeys would have failed, and also that it will work for other people as well. -- Enjoy, Tony "Anthony Giorgianni" wrote in message ... Thanks Tony. I found the problem. On my old laptop, I must have assigned F5 to turn on hgihlighting. So when I transferred the macro to my new laptop with "Sendkey" F5, it didn't trigger the highlighter but instead ran Find and replace, the assignment for f5 on that machine :O) Now it works fine with: Sub HighLight_Red() Selection.Range.HighlightColorIndex = wdRed SendKeys "(F10)" With F10 now assigned to turn on highlighting. End Sub Thanks again to you and Lene. Regards, Anthony Giorgianni For everyone's benefit, please reply to the group. |
#15
Posted to microsoft.public.word.newusers
|
|||
|
|||
Macro for highlighting
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 "Anthony Giorgianni" d wrote in message ... Thanks Tony But without using Sendkey, I can't figure out how simply to turn on highlighting without selecting anything first. Am I missing something? -- Regards, Anthony Giorgianni The return address for this post is fictitious. Please reply by posting back to the newsgroup. "Tony Jollans" My forename at my surname dot com wrote in message ... Whilst that may work for you ... * most people don't have F10 - or any key - assigned to highlighting * Sendkeys is generally best avoided If you use the explicit statement (Selection.Range.HighlightColorIndex = wdRed) that Lene and I have both suggested you will find it works just as well. The only difference (which you'll generally be unaware of) is that it will work when Sendkeys would have failed, and also that it will work for other people as well. -- Enjoy, Tony "Anthony Giorgianni" wrote in message ... Thanks Tony. I found the problem. On my old laptop, I must have assigned F5 to turn on hgihlighting. So when I transferred the macro to my new laptop with "Sendkey" F5, it didn't trigger the highlighter but instead ran Find and replace, the assignment for f5 on that machine :O) Now it works fine with: Sub HighLight_Red() Selection.Range.HighlightColorIndex = wdRed SendKeys "(F10)" With F10 now assigned to turn on highlighting. End Sub Thanks again to you and Lene. Regards, Anthony Giorgianni For everyone's benefit, please reply to the group. |
#16
Posted to microsoft.public.word.newusers
|
|||
|
|||
Macro for highlighting
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 |
#17
Posted to microsoft.public.word.newusers
|
|||
|
|||
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 |
#18
Posted to microsoft.public.word.newusers
|
|||
|
|||
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. |
#19
Posted to microsoft.public.word.newusers
|
|||
|
|||
Macro for highlighting
Greg,
About changing the previous highlighting too: after reading the description again now, I am sure you are right - however, I did not read it that way first. About the insertion point being in a word: you are right, if the option €œWhen selecting, automatically select entire word€ in Tools Options Edit tab is turned on, the code line "Selection.Range.HighlightColorIndex = wdRed" would highlight that word. I should have taken this into consideration by making a check in the code as you did in your version - unfortunately, I failed to notice this because I do not have that option turned on€¦ -- Regards Lene Fredborg DocTools - Denmark www.thedoctools.com Document automation - add-ins, macros and templates for Microsoft Word "Greg Maxey" wrote: 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. |
#20
Posted to microsoft.public.word.newusers
|
|||
|
|||
Macro for highlighting
Thanks everyone for your help.
I think I'll simply to stick with using the sendkeys command. That's a neat macro Lene but doesn't seem to do what I'm looking for. I think I'm probably not explaining it right. All I want to be able to do is simply turn on highlighting with a certain color with one click, avoiding having to go up to the highlighting menu item, select the color and turn it on. The reason is that, as a journalist, many times I'm reading a document and want to highlight items for different importance - green = interesting but not critical, yellow = pretty important, red = information that I must use. So when I see something pretty important, I want to turn on yellow highlighting with one click of a toolbar icon. Then I highlight that (usually without selecting it first) Later I might see something that's critical, so I want to turn on red highlighting with one click. This does that exactly Options.DefaultHighlightColorIndex = wdYellow REM: Selects the highlighting color yellow SendKeys "{F5}" REM Turns on highlighting, where Word has been set to associate F5 with turning on highlighting. Tony suggested that using sendkeys isn't the best way to do this. It certainly doesn't make the macro portable if I want to transfer it to another machine without having to set F5 (as I found out when I tried to transfer it from my home to my work machine and forgot about setting F5 to turn on highlighting.) So I was curious if there was another way to do it. But it's no big deal. It works fine. By the way, to make it really easy, I created a "highlighting" toolbar with icons that are simply colored squares, each assigned to a different color macro and one assigned to "no color" for clearing. Thanks again. Regards Anthony Giorgianni For everyone's benefit, please reply to the group. "Lene Fredborg" wrote in message ... Greg, About changing the previous highlighting too: after reading the description again now, I am sure you are right - however, I did not read it that way first. About the insertion point being in a word: you are right, if the option "When selecting, automatically select entire word" in Tools Options Edit tab is turned on, the code line "Selection.Range.HighlightColorIndex = wdRed" would highlight that word. I should have taken this into consideration by making a check in the code as you did in your version - unfortunately, I failed to notice this because I do not have that option turned on. -- Regards Lene Fredborg DocTools - Denmark www.thedoctools.com Document automation - add-ins, macros and templates for Microsoft Word |
#21
Posted to microsoft.public.word.newusers
|
|||
|
|||
Macro for highlighting
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 "Anthony Giorgianni" wrote: Thanks everyone for your help. I think I'll simply to stick with using the sendkeys command. That's a neat macro Lene but doesn't seem to do what I'm looking for. I think I'm probably not explaining it right. All I want to be able to do is simply turn on highlighting with a certain color with one click, avoiding having to go up to the highlighting menu item, select the color and turn it on. The reason is that, as a journalist, many times I'm reading a document and want to highlight items for different importance - green = interesting but not critical, yellow = pretty important, red = information that I must use. So when I see something pretty important, I want to turn on yellow highlighting with one click of a toolbar icon. Then I highlight that (usually without selecting it first) Later I might see something that's critical, so I want to turn on red highlighting with one click. This does that exactly Options.DefaultHighlightColorIndex = wdYellow REM: Selects the highlighting color yellow SendKeys "{F5}" REM Turns on highlighting, where Word has been set to associate F5 with turning on highlighting. Tony suggested that using sendkeys isn't the best way to do this. It certainly doesn't make the macro portable if I want to transfer it to another machine without having to set F5 (as I found out when I tried to transfer it from my home to my work machine and forgot about setting F5 to turn on highlighting.) So I was curious if there was another way to do it. But it's no big deal. It works fine. By the way, to make it really easy, I created a "highlighting" toolbar with icons that are simply colored squares, each assigned to a different color macro and one assigned to "no color" for clearing. Thanks again. Regards Anthony Giorgianni For everyone's benefit, please reply to the group. "Lene Fredborg" wrote in message ... Greg, About changing the previous highlighting too: after reading the description again now, I am sure you are right - however, I did not read it that way first. About the insertion point being in a word: you are right, if the option "When selecting, automatically select entire word" in Tools Options Edit tab is turned on, the code line "Selection.Range.HighlightColorIndex = wdRed" would highlight that word. I should have taken this into consideration by making a check in the code as you did in your version - unfortunately, I failed to notice this because I do not have that option turned on. -- Regards Lene Fredborg DocTools - Denmark www.thedoctools.com Document automation - add-ins, macros and templates for Microsoft Word |
#22
Posted to microsoft.public.word.newusers
|
|||
|
|||
Macro for highlighting
Hey Lene
Thanks again. I'm sorry I'm not being clear . Or maybe I'm being dense :O). When I say I don't want to select the text first, I mean that: I'm simply reading through a document and want to turn on the highlighting tool - the thing that changes the cursor into a virtual highlighting pen that you swipe across any text to highlight. This avoids having to actually select the text at all. So the combined function is 1) set the desired highlighting color 2) turn on the highlighting tool. So the macro would be 1) Select the highlight color (which we all know how to do) 2) Turn on the highlighting tool to transform the cursor into a highlighting pen (which is the part I can't figure out how to do as part of the macro without sendkeys) Oddly, if a record a macro, I get the first step. But when I click on the highlighting box to actually turn on the highlighting tool, that action doesn't get recorded in the VB code. See what I mean? Regards, Anthony Giorgianni For everyone's benefit, please reply to the group. "Lene Fredborg" wrote in message ... 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 "Anthony Giorgianni" wrote: Thanks everyone for your help. I think I'll simply to stick with using the sendkeys command. That's a neat macro Lene but doesn't seem to do what I'm looking for. I think I'm probably not explaining it right. All I want to be able to do is simply turn on highlighting with a certain color with one click, avoiding having to go up to the highlighting menu item, select the color and turn it on. The reason is that, as a journalist, many times I'm reading a document and want to highlight items for different importance - green = interesting but not critical, yellow = pretty important, red = information that I must use. So when I see something pretty important, I want to turn on yellow highlighting with one click of a toolbar icon. Then I highlight that (usually without selecting it first) Later I might see something that's critical, so I want to turn on red highlighting with one click. This does that exactly Options.DefaultHighlightColorIndex = wdYellow REM: Selects the highlighting color yellow SendKeys "{F5}" REM Turns on highlighting, where Word has been set to associate F5 with turning on highlighting. Tony suggested that using sendkeys isn't the best way to do this. It certainly doesn't make the macro portable if I want to transfer it to another machine without having to set F5 (as I found out when I tried to transfer it from my home to my work machine and forgot about setting F5 to turn on highlighting.) So I was curious if there was another way to do it. But it's no big deal. It works fine. By the way, to make it really easy, I created a "highlighting" toolbar with icons that are simply colored squares, each assigned to a different color macro and one assigned to "no color" for clearing. Thanks again. Regards Anthony Giorgianni For everyone's benefit, please reply to the group. "Lene Fredborg" wrote in message ... Greg, About changing the previous highlighting too: after reading the description again now, I am sure you are right - however, I did not read it that way first. About the insertion point being in a word: you are right, if the option "When selecting, automatically select entire word" in Tools Options Edit tab is turned on, the code line "Selection.Range.HighlightColorIndex = wdRed" would highlight that word. I should have taken this into consideration by making a check in the code as you did in your version - unfortunately, I failed to notice this because I do not have that option turned on. -- Regards Lene Fredborg DocTools - Denmark www.thedoctools.com Document automation - add-ins, macros and templates for Microsoft Word |
#23
Posted to microsoft.public.word.newusers
|
|||
|
|||
Macro for highlighting
Yes, now - finally - I see what you mean :-)
And now I also understand what you meant by "usually without selecting it first". Happy highlighting! --- Regards Lene Fredborg DocTools - Denmark www.thedoctools.com Document automation - add-ins, macros and templates for Microsoft Word "Anthony Giorgianni" wrote: Hey Lene Thanks again. I'm sorry I'm not being clear . Or maybe I'm being dense :O). When I say I don't want to select the text first, I mean that: I'm simply reading through a document and want to turn on the highlighting tool - the thing that changes the cursor into a virtual highlighting pen that you swipe across any text to highlight. This avoids having to actually select the text at all. So the combined function is 1) set the desired highlighting color 2) turn on the highlighting tool. So the macro would be 1) Select the highlight color (which we all know how to do) 2) Turn on the highlighting tool to transform the cursor into a highlighting pen (which is the part I can't figure out how to do as part of the macro without sendkeys) Oddly, if a record a macro, I get the first step. But when I click on the highlighting box to actually turn on the highlighting tool, that action doesn't get recorded in the VB code. See what I mean? Regards, Anthony Giorgianni For everyone's benefit, please reply to the group. "Lene Fredborg" wrote in message ... 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 "Anthony Giorgianni" wrote: Thanks everyone for your help. I think I'll simply to stick with using the sendkeys command. That's a neat macro Lene but doesn't seem to do what I'm looking for. I think I'm probably not explaining it right. All I want to be able to do is simply turn on highlighting with a certain color with one click, avoiding having to go up to the highlighting menu item, select the color and turn it on. The reason is that, as a journalist, many times I'm reading a document and want to highlight items for different importance - green = interesting but not critical, yellow = pretty important, red = information that I must use. So when I see something pretty important, I want to turn on yellow highlighting with one click of a toolbar icon. Then I highlight that (usually without selecting it first) Later I might see something that's critical, so I want to turn on red highlighting with one click. This does that exactly Options.DefaultHighlightColorIndex = wdYellow REM: Selects the highlighting color yellow SendKeys "{F5}" REM Turns on highlighting, where Word has been set to associate F5 with turning on highlighting. Tony suggested that using sendkeys isn't the best way to do this. It certainly doesn't make the macro portable if I want to transfer it to another machine without having to set F5 (as I found out when I tried to transfer it from my home to my work machine and forgot about setting F5 to turn on highlighting.) So I was curious if there was another way to do it. But it's no big deal. It works fine. By the way, to make it really easy, I created a "highlighting" toolbar with icons that are simply colored squares, each assigned to a different color macro and one assigned to "no color" for clearing. Thanks again. Regards Anthony Giorgianni For everyone's benefit, please reply to the group. "Lene Fredborg" wrote in message ... Greg, About changing the previous highlighting too: after reading the description again now, I am sure you are right - however, I did not read it that way first. About the insertion point being in a word: you are right, if the option "When selecting, automatically select entire word" in Tools Options Edit tab is turned on, the code line "Selection.Range.HighlightColorIndex = wdRed" would highlight that word. I should have taken this into consideration by making a check in the code as you did in your version - unfortunately, I failed to notice this because I do not have that option turned on. -- Regards Lene Fredborg DocTools - Denmark www.thedoctools.com Document automation - add-ins, macros and templates for Microsoft Word |
#24
Posted to microsoft.public.word.newusers
|
|||
|
|||
Macro for highlighting
Thanks again for all your help!!!!
Regards Anthony Giorgianni For everyone's benefit, please reply to the group. "Lene Fredborg" wrote in message ... Yes, now - finally - I see what you mean :-) And now I also understand what you meant by "usually without selecting it first". Happy highlighting! --- Regards Lene Fredborg DocTools - Denmark www.thedoctools.com Document automation - add-ins, macros and templates for Microsoft Word |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Form Generaters in Word | Microsoft Word Help | |||
macro produces error message | Microsoft Word Help | |||
Macro Button Won't Stay on Toolbar | Microsoft Word Help | |||
Possible bug when recording a Word Macro | Microsoft Word Help | |||
2000 to 2002 macro and "Could not open macro storage" | Mailmerge |