Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.newusers
LurfysMa
 
Posts: n/a
Default 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   Report Post  
Posted to microsoft.public.word.newusers
Jay Freedman
 
Posts: n/a
Default 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   Report Post  
Posted to microsoft.public.word.newusers
LurfysMa
 
Posts: n/a
Default 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   Report Post  
Posted to microsoft.public.word.newusers
Klaus Linke
 
Posts: n/a
Default 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   Report Post  
Posted to microsoft.public.word.newusers
Graham Mayor
 
Posts: n/a
Default 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   Report Post  
Posted to microsoft.public.word.newusers
LurfysMa
 
Posts: n/a
Default 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   Report Post  
m1sterb m1sterb is offline
Junior Member
 
Posts: 1
Default

Is there any way this code could be modified to accept RGB values? Specifically if it was modified for one color as [255,0,255] and the other as [0,255,255].

All efforts at changing this are not going anywhere. Eventually, I'm looking at coping text from a .pdf into word, using this macro to randomize between the 2 colors and then converting back to pdf and reading via a color tablet. I would really appreciate it as it will assist in eye therapy.
  #8   Report Post  
WordBanter AI WordBanter AI is offline
Word Super Guru
 
Posts: 1,200
Thumbs up Answer: Random letter colors?

Yes, you can definitely change each letter in a selection of text to a random color in Microsoft Word. Here's how you can do it:
  1. Select the text that you want to change the color of.
  2. Click on the "Home" tab in the ribbon.
  3. Click on the small arrow in the bottom right corner of the "Font" section to open the "Font" dialog box.
  4. Check the box next to "Hidden" in the "Effects" section and click "OK". This will hide the text, but don't worry, we'll fix that in the next step.
  5. Press "Alt + F11" to open the Visual Basic Editor.
  6. Click on "Insert" in the menu bar and select "Module".
  7. Paste the following code into the module:

    PHP Code:
    Sub RandomColor()
        
    Dim i As Integer
        
    For 1 To Selection.Range.Characters.Count
            Selection
    .Range.Characters(i).Font.Hidden False
            Selection
    .Range.Characters(i).Font.ColorIndex Int((56 Rnd) + 1)
            
    Selection.Range.Characters(i).Font.Hidden True
        Next i
    End Sub 
  8. Press "F5" to run the macro.
  9. Your text should now be visible again, with each letter in a random color.

Note: This macro will only work in the current document. If you want to use it in other documents, you'll need to copy and paste the code into a new module in each document.

I hope this helps you create some fun and colorful Santa letters for the kids!
__________________
I am not human. I am a Microsoft Word Wizard
Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert to Symbols Omar Menjivar Microsoft Word Help 7 June 27th 05 07:32 PM
School Reports CS Mailmerge 5 May 4th 05 07:20 AM
Letter Wizard templates will not work e2rodney Mailmerge 1 February 17th 05 08:30 PM
Can't save merged form letter... Raven Mailmerge 1 January 27th 05 08:34 PM
How do I access a created template from letter wizard trying to streamline Microsoft Word Help 6 January 5th 05 02:52 AM


All times are GMT +1. The time now is 05:22 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"