![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| | |||||||
| | Vista - Highlighting a selection in word document |
| |
| 11-12-2008 | #1 |
| | Highlighting a selection in word document I'm trying to write some code that highlights a selection in a word document. The code gets the correct selection and I'm able to do things like set the font type and make the font bold of the correct selection. However, I have also been asked to highlight the selection in yellow. The code I'm using is: With objSelection.Font .Bold = True .Italic = False .Name = "Arial" End With objSelection.HighlightColorIndex = wdYellow In this code, the with block executes perfectly, but I can't get the highlighting part to work. Does anybody have a suggestion? Thanks. |
| My System Specs |
| 11-12-2008 | #2 |
| | Re: Highlighting a selection in word document You need to find the value of wdYellow and use that, or define wdYellow as a constant. Only Word knows what wdYellow is - to your script it's just an undefined variable. Tim <jbrusoe@xxxxxx> wrote in message news:91ff03ea-e178-46ef-a825-d4d966bbf4c2@xxxxxx Quote: > I'm trying to write some code that highlights a selection in a word > document. The code gets the correct selection and I'm able to do > things like set the font type and make the font bold of the correct > selection. However, I have also been asked to highlight the selection > in yellow. The code I'm using is: > > With objSelection.Font > .Bold = True > .Italic = False > .Name = "Arial" > End With > > objSelection.HighlightColorIndex = wdYellow > > In this code, the with block executes perfectly, but I can't get the > highlighting part to work. Does anybody have a suggestion? > > Thanks. |
| My System Specs |
| 11-12-2008 | #3 |
| | Re: Highlighting a selection in word document Thanks for the reply. However, I thought wdYellow was predefined. I got that from this article: http://msdn.microsoft.com/en-us/libr...ffice.10).aspx Also, when I change the font color, I was using something like .Color = RGB(255,255,0). I know that works. When I tried that color value (the RGB notation) with HighlightColorIndex, nothing happens. So I was wondering if this is even the correct property to be using? Thanks again. On Nov 12, 6:53*pm, "Tim Williams" <timjwilliams at gmail dot com> wrote: Quote: > You need to find the value of wdYellow and use that, or define wdYellow as a > constant. > Only Word knows what wdYellow is - to your script it's just an undefined > variable. > > Tim > > <jbru...@xxxxxx> wrote in message > > news:91ff03ea-e178-46ef-a825-d4d966bbf4c2@xxxxxx > Quote: > > I'm trying to write some code that highlights a selection in a word > > document. *The code gets the correct selection and I'm able to do > > things like set the font type and make the font bold of the correct > > selection. *However, I have also been asked to highlight the selection > > in yellow. *The code I'm using is: Quote: > > With objSelection.Font > > * .Bold = True > > * .Italic = False > > * .Name = "Arial" > > End With Quote: > > objSelection.HighlightColorIndex = wdYellow Quote: > > In this code, the with block executes perfectly, but I can't get the > > highlighting part to work. Does anybody have a suggestion? Quote: > > Thanks. |
| My System Specs |
| 11-13-2008 | #4 |
| | Re: Highlighting a selection in word document wdYellow *is* pre-defined, but only if you're prgramming in Word VBA or have added a reference to the Word object library. Since you're posting in the vbscript group I'm assuming you're using vbscript. ColorIndex usually refers to one of a set of predefined colors, such as those found on the Excel 56(?) color pallette. Have you tried just .Color (though that isn't in the list of properties at your MS URL) ? Tim <jbrusoe@xxxxxx> wrote in message news:60460a11-be35-4ea8-9f68-4e08d3950280@xxxxxx Thanks for the reply. However, I thought wdYellow was predefined. I got that from this article: http://msdn.microsoft.com/en-us/libr...ffice.10).aspx Also, when I change the font color, I was using something like .Color = RGB(255,255,0). I know that works. When I tried that color value (the RGB notation) with HighlightColorIndex, nothing happens. So I was wondering if this is even the correct property to be using? Thanks again. On Nov 12, 6:53 pm, "Tim Williams" <timjwilliams at gmail dot com> wrote: Quote: > You need to find the value of wdYellow and use that, or define wdYellow as > a > constant. > Only Word knows what wdYellow is - to your script it's just an undefined > variable. > > Tim > > <jbru...@xxxxxx> wrote in message > > news:91ff03ea-e178-46ef-a825-d4d966bbf4c2@xxxxxx > Quote: > > I'm trying to write some code that highlights a selection in a word > > document. The code gets the correct selection and I'm able to do > > things like set the font type and make the font bold of the correct > > selection. However, I have also been asked to highlight the selection > > in yellow. The code I'm using is: Quote: > > With objSelection.Font > > .Bold = True > > .Italic = False > > .Name = "Arial" > > End With Quote: > > objSelection.HighlightColorIndex = wdYellow Quote: > > In this code, the with block executes perfectly, but I can't get the > > highlighting part to work. Does anybody have a suggestion? Quote: > > Thanks. |
| My System Specs |
| 11-13-2008 | #5 |
| | Re: Highlighting a selection in word document Thanks again for the reply and that clarifies a lot. You are correct that I'm using vbscript to try and automate some settings in word. However, I'm still confused about a few things. 1. When I wrote a macro and selected the highlight option and then looked at the code, the code for the macro had the HighlightColorIndex set. If I choose that option for the selection I want, why wouldn't the RGB(255,255,0) setting work? I can use this same format to change the font color and assumed it would work for the highlighting as well. 2. The code I'm currently using is: With objSelection.Font .Bold = True .Italic = False .Name = "Arial" .Color = RGB(255,0,0) End With objSelection.HighlightColorIndex.Color = RGB(255,255,0) In this code, the with block code is executed perfectly, but the HighlighColorIndex doesn't make any changes. I've tried this with and without the .Color at the end. Unfortunately, for this app, that is probably the most important setting that is needed. Any other suggestions to have a rectangular shape highlighted yellow around the selected words? Thanks again. On Nov 13, 1:41*am, "Tim Williams" <timjwilliams at gmail dot com> wrote: Quote: > wdYellow *is* pre-defined, but only if you're prgramming in Word VBA or have > added a reference to the Word object library. > Since you're posting in the vbscript group I'm assuming you're using > vbscript. > > ColorIndex usually refers to one of a set of predefined colors, such as > those found on the Excel 56(?) color pallette. > Have you tried just .Color (though that isn't in the list of properties at > your MS URL) ? > > Tim > > <jbru...@xxxxxx> wrote in message > > news:60460a11-be35-4ea8-9f68-4e08d3950280@xxxxxx > Thanks for the reply. *However, I thought wdYellow was predefined. *I > got that from this article:http://msdn.microsoft.com/en-us/libr...ffice.10).aspx > > Also, when I change the font color, I was using something like .Color > = RGB(255,255,0). *I know that works. *When I tried that color value > (the RGB notation) with HighlightColorIndex, nothing happens. *So I > was wondering if this is even the correct property to be using? > > Thanks again. > > On Nov 12, 6:53 pm, "Tim Williams" <timjwilliams at gmail dot com> > wrote: > > > Quote: > > You need to find the value of wdYellow and use that, or define wdYellowas > > a > > constant. > > Only Word knows what wdYellow is - to your script it's just an undefined > > variable. Quote: > > Tim Quote: > > <jbru...@xxxxxx> wrote in message Quote: > >news:91ff03ea-e178-46ef-a825-d4d966bbf4c2@xxxxxx Quote: Quote: > > > I'm trying to write some code that highlights a selection in a word > > > document. The code gets the correct selection and I'm able to do > > > things like set the font type and make the font bold of the correct > > > selection. However, I have also been asked to highlight the selection > > > in yellow. The code I'm using is: Quote: Quote: > > > With objSelection.Font > > > .Bold = True > > > .Italic = False > > > .Name = "Arial" > > > End With Quote: Quote: > > > objSelection.HighlightColorIndex = wdYellow Quote: Quote: > > > In this code, the with block executes perfectly, but I can't get the > > > highlighting part to work. Does anybody have a suggestion? Quote: Quote: > > > Thanks.- Hide quoted text - > - Show quoted text - |
| My System Specs |
| 11-13-2008 | #6 |
| | Re: Highlighting a selection in word document 1. A property like ".xxxColorIndex" typically is not the same as ".xxxColor" (which usually is OK with a RGB value). Look at the object browser in the Word VBE (F2) to see why: the expected parameter for HighlightColorIndex is "Enum WdColorIndex" - ie. one of a set of pre-defined values represented by constants such as wdYellow, whose actual *value* is 7. RGB() returns a Long, so RGB(255,255,0) is 65535. And you can't just tag on .Color behind .HighlightColorIndex. 2. So, don't do this: objSelection.HighlightColorIndex.Color = RGB(255,255,0) Do this: objSelection.HighlightColorIndex = 7 Tim "Jeff" <jbrusoe@xxxxxx> wrote in message news:4300b92c-d3e1-47a5-a12d-517d0f139112@xxxxxx Thanks again for the reply and that clarifies a lot. You are correct that I'm using vbscript to try and automate some settings in word. However, I'm still confused about a few things. 1. When I wrote a macro and selected the highlight option and then looked at the code, the code for the macro had the HighlightColorIndex set. If I choose that option for the selection I want, why wouldn't the RGB(255,255,0) setting work? I can use this same format to change the font color and assumed it would work for the highlighting as well. I'm more familiar with 2. The code I'm currently using is: With objSelection.Font .Bold = True .Italic = False .Name = "Arial" .Color = RGB(255,0,0) End With objSelection.HighlightColorIndex.Color = RGB(255,255,0) In this code, the with block code is executed perfectly, but the HighlighColorIndex doesn't make any changes. I've tried this with and without the .Color at the end. Unfortunately, for this app, that is probably the most important setting that is needed. Any other suggestions to have a rectangular shape highlighted yellow around the selected words? Thanks again. On Nov 13, 1:41 am, "Tim Williams" <timjwilliams at gmail dot com> wrote: Quote: > wdYellow *is* pre-defined, but only if you're prgramming in Word VBA or > have > added a reference to the Word object library. > Since you're posting in the vbscript group I'm assuming you're using > vbscript. > > ColorIndex usually refers to one of a set of predefined colors, such as > those found on the Excel 56(?) color pallette. > Have you tried just .Color (though that isn't in the list of properties at > your MS URL) ? > > Tim > > <jbru...@xxxxxx> wrote in message > > news:60460a11-be35-4ea8-9f68-4e08d3950280@xxxxxx > Thanks for the reply. However, I thought wdYellow was predefined. I > got that from this > article:http://msdn.microsoft.com/en-us/libr...ffice.10).aspx > > Also, when I change the font color, I was using something like .Color > = RGB(255,255,0). I know that works. When I tried that color value > (the RGB notation) with HighlightColorIndex, nothing happens. So I > was wondering if this is even the correct property to be using? > > Thanks again. > > On Nov 12, 6:53 pm, "Tim Williams" <timjwilliams at gmail dot com> > wrote: > > > Quote: > > You need to find the value of wdYellow and use that, or define wdYellow > > as > > a > > constant. > > Only Word knows what wdYellow is - to your script it's just an undefined > > variable. Quote: > > Tim Quote: > > <jbru...@xxxxxx> wrote in message Quote: > >news:91ff03ea-e178-46ef-a825-d4d966bbf4c2@xxxxxx Quote: Quote: > > > I'm trying to write some code that highlights a selection in a word > > > document. The code gets the correct selection and I'm able to do > > > things like set the font type and make the font bold of the correct > > > selection. However, I have also been asked to highlight the selection > > > in yellow. The code I'm using is: Quote: Quote: > > > With objSelection.Font > > > .Bold = True > > > .Italic = False > > > .Name = "Arial" > > > End With Quote: Quote: > > > objSelection.HighlightColorIndex = wdYellow Quote: Quote: > > > In this code, the with block executes perfectly, but I can't get the > > > highlighting part to work. Does anybody have a suggestion? Quote: Quote: > > > Thanks.- Hide quoted text - > - Show quoted text - |
| My System Specs |
![]() |
| Thread Tools | |
| |
| Similar Threads for: Highlighting a selection in word document | ||||
| Thread | Forum | |||
| Word 2007 highlighting question | Vista General | |||
| "Selection" highlighting in Explorer/Mail etc | Vista General | |||
| Word 2007 - word or phrase selection highlight colour | Vista General | |||
| accidentally moved a MS Word document,now it dissapears everytime i open any word document | Vista performance & maintenance | |||
| accidentally moved a MS Word document,now it dissapears everytime i open any word document | Vista General | |||