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 |
#1
|
|||
|
|||
Random letter colors?
Is there any way to get Word to change each letter in a selection of
text to a random color? I am writing some Santa letters to some kids in a playful font and I would like to print them in color. I guess I could write a little macro. -- Running Word 2000 SP-3 on Windows 2000 |
#2
|
|||
|
|||
Random letter colors?
On Fri, 23 Dec 2005 16:34:09 -0800, LurfysMa
wrote: Is there any way to get Word to change each letter in a selection of text to a random color? I am writing some Santa letters to some kids in a playful font and I would like to print them in color. I guess I could write a little macro. You could write a little macro, but you might find a little wrinkle that needs to be worked out. Yellow and white characters don't print very well. g Try this: Sub RandomColors() Dim oCh As Range Dim myColor As Word.WdColorIndex Randomize For Each oCh In ActiveDocument.Characters Do ' get a random color that isn't white or yellow myColor = 14 * Rnd() + 1 Loop Until (myColor wdWhite) And (myColor wdYellow) oCh.Font.ColorIndex = myColor Next oCh End Sub -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. |
#3
|
|||
|
|||
Random letter colors?
On Fri, 23 Dec 2005 21:55:57 -0500, Jay Freedman
wrote: On Fri, 23 Dec 2005 16:34:09 -0800, LurfysMa wrote: Is there any way to get Word to change each letter in a selection of text to a random color? I am writing some Santa letters to some kids in a playful font and I would like to print them in color. I guess I could write a little macro. You could write a little macro, but you might find a little wrinkle that needs to be worked out. Yellow and white characters don't print very well. g Try this: Sub RandomColors() Dim oCh As Range Dim myColor As Word.WdColorIndex Randomize For Each oCh In ActiveDocument.Characters Do ' get a random color that isn't white or yellow myColor = 14 * Rnd() + 1 Loop Until (myColor wdWhite) And (myColor wdYellow) oCh.Font.ColorIndex = myColor Next oCh End Sub Wow. That is slick. I had a much more complicated macro going. Can I ask you to tweak it so that it (a) Only works on the currently selected text, and (b) Only uses a predefined list of colors (red, green, blue, for example)? Thanks -- Running Word 2000 SP-3 on Windows 2000 |
#4
|
|||
|
|||
Random letter colors?
Hi LurfysMa,
Can I ask you to tweak it so that it (a) Only works on the currently selected text, and Easy: change ActiveDocument to Selection. (b) Only uses a predefined list of colors (red, green, blue, for example)? One possibility is a Select Case, but for the heck of it, I used Switch: Sub RandomColors() Dim oCh As Range Dim myColor As Word.WdColorIndex Randomize For Each oCh In Selection.Characters myColor = Int(3 * Rnd()) oCh.Font.ColorIndex = _ Switch(myColor = 0, wdBlue, _ myColor = 1, wdRed, _ myColor = 2, wdGreen) Next oCh End Sub Regards, Klaus "LurfysMa" schrieb im Newsbeitrag ... On Fri, 23 Dec 2005 21:55:57 -0500, Jay Freedman wrote: On Fri, 23 Dec 2005 16:34:09 -0800, LurfysMa wrote: Is there any way to get Word to change each letter in a selection of text to a random color? I am writing some Santa letters to some kids in a playful font and I would like to print them in color. I guess I could write a little macro. You could write a little macro, but you might find a little wrinkle that needs to be worked out. Yellow and white characters don't print very well. g Try this: Sub RandomColors() Dim oCh As Range Dim myColor As Word.WdColorIndex Randomize For Each oCh In ActiveDocument.Characters Do ' get a random color that isn't white or yellow myColor = 14 * Rnd() + 1 Loop Until (myColor wdWhite) And (myColor wdYellow) oCh.Font.ColorIndex = myColor Next oCh End Sub Wow. That is slick. I had a much more complicated macro going. Can I ask you to tweak it so that it (a) Only works on the currently selected text, and (b) Only uses a predefined list of colors (red, green, blue, for example)? Thanks -- Running Word 2000 SP-3 on Windows 2000 |
#5
|
|||
|
|||
Random letter colors?
Another possibility is the inverse of Jay's code
Sub RandomColors() Dim oCh As Range Dim myColor As Word.WdColorIndex Randomize For Each oCh In Selection.Characters Do myColor = 14 * Rnd() + 1 Loop Until (myColor = wdBlue) Or (myColor = wdRed) Or (myColor = wdGreen) oCh.Font.ColorIndex = myColor Next oCh End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Klaus Linke wrote: Hi LurfysMa, Can I ask you to tweak it so that it (a) Only works on the currently selected text, and Easy: change ActiveDocument to Selection. (b) Only uses a predefined list of colors (red, green, blue, for example)? One possibility is a Select Case, but for the heck of it, I used Switch: Sub RandomColors() Dim oCh As Range Dim myColor As Word.WdColorIndex Randomize For Each oCh In Selection.Characters myColor = Int(3 * Rnd()) oCh.Font.ColorIndex = _ Switch(myColor = 0, wdBlue, _ myColor = 1, wdRed, _ myColor = 2, wdGreen) Next oCh End Sub Regards, Klaus "LurfysMa" schrieb im Newsbeitrag ... On Fri, 23 Dec 2005 21:55:57 -0500, Jay Freedman wrote: On Fri, 23 Dec 2005 16:34:09 -0800, LurfysMa wrote: Is there any way to get Word to change each letter in a selection of text to a random color? I am writing some Santa letters to some kids in a playful font and I would like to print them in color. I guess I could write a little macro. You could write a little macro, but you might find a little wrinkle that needs to be worked out. Yellow and white characters don't print very well. g Try this: Sub RandomColors() Dim oCh As Range Dim myColor As Word.WdColorIndex Randomize For Each oCh In ActiveDocument.Characters Do ' get a random color that isn't white or yellow myColor = 14 * Rnd() + 1 Loop Until (myColor wdWhite) And (myColor wdYellow) oCh.Font.ColorIndex = myColor Next oCh End Sub Wow. That is slick. I had a much more complicated macro going. Can I ask you to tweak it so that it (a) Only works on the currently selected text, and (b) Only uses a predefined list of colors (red, green, blue, for example)? Thanks -- Running Word 2000 SP-3 on Windows 2000 |
#6
|
|||
|
|||
Random letter colors?
On Sat, 24 Dec 2005 16:08:20 +0200, "Graham Mayor"
wrote: Another possibility is the inverse of Jay's code Sub RandomColors() Dim oCh As Range Dim myColor As Word.WdColorIndex Randomize For Each oCh In Selection.Characters Do myColor = 14 * Rnd() + 1 Loop Until (myColor = wdBlue) Or (myColor = wdRed) Or (myColor = wdGreen) oCh.Font.ColorIndex = myColor Next oCh End Sub I was thinking of defining an array to hold the desired list of colors. I'll have to figure out what the numbers are for red and green (for Christmas letters). Then I could either select them randomly or cycle through them. I'll play with these variations. Thanks -- Running Word 2000 SP-3 on Windows 2000 |
#7
|
|||
|
|||
Random letter colors?
On Sat, 24 Dec 2005 07:41:05 -0800, LurfysMa
wrote: On Sat, 24 Dec 2005 16:08:20 +0200, "Graham Mayor" wrote: Another possibility is the inverse of Jay's code Sub RandomColors() Dim oCh As Range Dim myColor As Word.WdColorIndex Randomize For Each oCh In Selection.Characters Do myColor = 14 * Rnd() + 1 Loop Until (myColor = wdBlue) Or (myColor = wdRed) Or (myColor = wdGreen) oCh.Font.ColorIndex = myColor Next oCh End Sub I was thinking of defining an array to hold the desired list of colors. I'll have to figure out what the numbers are for red and green (for Christmas letters). Then I could either select them randomly or cycle through them. I'll play with these variations. Thanks To find the numbers, go into the VBA editor and press F2 to open the Object Browser. Type wdColorIndex into the search box and press Enter. Near the bottom right you'll see a list of "Members of wdColorIndex" with the names. Click any color name and look at the bottom-most pane to see its numeric value. Another way is to open the Immediate window in the editor (shortcut is Ctrl+G) and type a question mark followed by the color name. When you press Enter, the value will be printed below (because the question mark is shorthand for the Print command). For example, ?wdRed displays the value 6. Finally, you don't have to know the numbers at all. You can do something like this: Dim ColorArray(2) As WdColorIndex ' declares 3 elements 0,1,2 Dim myColor As WdColorIndex ColorArray(0) = wdBlue ColorArray(1) = wdRed ColorArray(2) = wdGreen and then in the For Each loop select one element from the array this way: myColor = ColorArray(Int(3 * Rnd())) The 3 in this statement is the number of elements in the array -- it could also be written as myColor = ColorArray(Int((UBound(ColorArray) + 1) * Rnd())) -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. |
#8
|
|||
|
|||
Random letter colors?
Am I missing something here - if the aim of this was as originally described
"I am writing some Santa letters to some kids in a playful font and I would like to print them in color" then what's the point of the extra sophistication? Any of the suggestions posted would do the job. Macros are there to help you work, not to spend more time on them than the original job they replace. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org LurfysMa wrote: On Sat, 24 Dec 2005 16:08:20 +0200, "Graham Mayor" wrote: Another possibility is the inverse of Jay's code Sub RandomColors() Dim oCh As Range Dim myColor As Word.WdColorIndex Randomize For Each oCh In Selection.Characters Do myColor = 14 * Rnd() + 1 Loop Until (myColor = wdBlue) Or (myColor = wdRed) Or (myColor = wdGreen) oCh.Font.ColorIndex = myColor Next oCh End Sub I was thinking of defining an array to hold the desired list of colors. I'll have to figure out what the numbers are for red and green (for Christmas letters). Then I could either select them randomly or cycle through them. I'll play with these variations. Thanks |
#9
|
|||
|
|||
Random letter colors?
I have been biting my tongue through this entire thread. I think the idea of
random colors for text (if by random we're talking about alternating between letters) is a *terrible* idea that should have been nipped in the bud! -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Graham Mayor" wrote in message ... Am I missing something here - if the aim of this was as originally described "I am writing some Santa letters to some kids in a playful font and I would like to print them in color" then what's the point of the extra sophistication? Any of the suggestions posted would do the job. Macros are there to help you work, not to spend more time on them than the original job they replace. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org LurfysMa wrote: On Sat, 24 Dec 2005 16:08:20 +0200, "Graham Mayor" wrote: Another possibility is the inverse of Jay's code Sub RandomColors() Dim oCh As Range Dim myColor As Word.WdColorIndex Randomize For Each oCh In Selection.Characters Do myColor = 14 * Rnd() + 1 Loop Until (myColor = wdBlue) Or (myColor = wdRed) Or (myColor = wdGreen) oCh.Font.ColorIndex = myColor Next oCh End Sub I was thinking of defining an array to hold the desired list of colors. I'll have to figure out what the numbers are for red and green (for Christmas letters). Then I could either select them randomly or cycle through them. I'll play with these variations. Thanks |
#10
|
|||
|
|||
Random letter colors?
I think a lot depends on the target audience and the purpose of the
document. A letter from Santa would be one of the few instances when something like this is acceptable. (To be honest - I can't really think of another use but I don't usually produce documents where multi-colored fonts would be appreciated. They just don't seem to have a place in a medical practice. -- JoAnn Paules MVP Microsoft [Publisher] "Suzanne S. Barnhill" wrote in message ... I have been biting my tongue through this entire thread. I think the idea of random colors for text (if by random we're talking about alternating between letters) is a *terrible* idea that should have been nipped in the bud! -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Graham Mayor" wrote in message ... Am I missing something here - if the aim of this was as originally described "I am writing some Santa letters to some kids in a playful font and I would like to print them in color" then what's the point of the extra sophistication? Any of the suggestions posted would do the job. Macros are there to help you work, not to spend more time on them than the original job they replace. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org LurfysMa wrote: On Sat, 24 Dec 2005 16:08:20 +0200, "Graham Mayor" wrote: Another possibility is the inverse of Jay's code Sub RandomColors() Dim oCh As Range Dim myColor As Word.WdColorIndex Randomize For Each oCh In Selection.Characters Do myColor = 14 * Rnd() + 1 Loop Until (myColor = wdBlue) Or (myColor = wdRed) Or (myColor = wdGreen) oCh.Font.ColorIndex = myColor Next oCh End Sub I was thinking of defining an array to hold the desired list of colors. I'll have to figure out what the numbers are for red and green (for Christmas letters). Then I could either select them randomly or cycle through them. I'll play with these variations. Thanks |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
VBA "Rnd" Function: Truly Random? | TheRobsterUK | General Discussion | 2 | September 27th, 2005 04:50 AM |
word replaced or letter changed removes the next letter word?? | word replacement? | Running & Setting Up Queries | 1 | May 4th, 2005 03:39 AM |
Make a hidden phrase appear, letter by letter, in random order | Jimmy G | Powerpoint | 5 | April 29th, 2005 07:52 PM |
Random alpha generator | bj | Worksheet Functions | 3 | April 27th, 2005 11:02 PM |
New Letter to Contact | Gary | Contacts | 1 | July 23rd, 2004 02:36 PM |