If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#11
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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 |
Thread Tools | |
Display Modes | |
|
|