Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-19-2013, 06:25 AM
skan skan is offline every letter different color Windows 7 64bit every letter different color Office 2010 64bit
Novice
every letter different color
 
Join Date: Mar 2013
Posts: 10
skan is on a distinguished road
Default every letter different color

Hello

I was just wondering how can I do to get, in a word document, every letter or word of a different color?
I guess there isn't any option to do it and I'll need a macro.
Could you post a simple macro to do it, please?

What about getting a gradient? I guess that each letter can only have one single solid color?



regards
Reply With Quote
  #2  
Old 03-19-2013, 03:26 PM
macropod's Avatar
macropod macropod is offline every letter different color Windows 7 64bit every letter different color Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Yes, it would require a macro. The following shows how to randomly colour each letter individually - just don't expect quick results. Note too that some colours will look quite similar to others (some may even be the same).
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim i As Long
Randomize Timer
With ActiveDocument
  For i = 1 To .Characters.Count
    .Characters(i).Font.Color = Int(Rnd * 1048576)
  Next
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 03-19-2013, 04:43 PM
skan skan is offline every letter different color Windows 7 64bit every letter different color Office 2010 64bit
Novice
every letter different color
 
Join Date: Mar 2013
Posts: 10
skan is on a distinguished road
Default

Thank you, macropod, it works.
I've tried it at my girlfriend's laptop, a very old one, and it takes 1 minute to change the colors of a single page. Now I understand what some people says that macros are very slow.

Regards
Reply With Quote
  #4  
Old 03-19-2013, 04:49 PM
macropod's Avatar
macropod macropod is offline every letter different color Windows 7 64bit every letter different color Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by skan View Post
I've tried it at my girlfriend's laptop, a very old one, and it takes 1 minute to change the colors of a single page. Now I understand what some people says that macros are very slow.
Actually, macros can do things very quickly. It's just that this one has a lot of work to do. Consider how long it would take you to change every character to a different colour manually and you'll get an idea of just how fast the macro is working. Of course, with a newer, faster PC, the macro would take even less time to do the job.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 03-19-2013, 04:55 PM
skan skan is offline every letter different color Windows 7 64bit every letter different color Office 2010 64bit
Novice
every letter different color
 
Join Date: Mar 2013
Posts: 10
skan is on a distinguished road
Default

But for a computer changing 1000 characters of colour is not too much. If I could program it with C++ (and worked not on a word document) it would be much faster.
I remeber using excel to perform calculus on very long rows and it gets really slow compared to other solutions.

Anyway, it's nice.

regards
Reply With Quote
  #6  
Old 03-19-2013, 05:00 PM
macropod's Avatar
macropod macropod is offline every letter different color Windows 7 64bit every letter different color Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

A c++ solution that automates a Word document to do the same job would actually be slower (because of the automation overheads) and it would probably use exactly the same process ... Of course, if you were not working on a Word document, that would be a different issue, but in this case you are working on a Word document.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 03-27-2013, 11:05 AM
gmaxey gmaxey is offline every letter different color Windows 7 32bit every letter different color Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,421
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Paul,

I've found that using a For .... Each rather that a For i = 1 to some.count is considerably faster in situations like this. Also by adding a collection and key you can prevent duplicate colors:

Code:
Sub MyRandCharColors16M_Augment()
Dim oCol As New Collection
Dim lngColor As Long
Dim oChr As Range
Dim sngR As Single, sngG As Single, snbB As Single
Dim sngRGBSum As Single, sngRGBF As Single
Application.ScreenUpdating = False
'Define the maximum RGB sum. A score around 500-600 seems to give the best results.
Const sngRGBMax As Single = 550
Randomize
'Loop thru characters in document.
For Each oChr In ActiveDocument.Range.Characters
Dup_Reentry:
  sngR = Int(Rnd() * 256)
  sngG = Int(Rnd() * 256)
  snbB = Int(Rnd() * 256)
  'If the sum > max, scale all three back proportionately
  sngRGBSum = sngR + sngG + snbB
  If sngRGBSum > sngRGBMax Then
    sngRGBF = sngRGBMax / sngRGBSum
    sngR = sngR * sngRGBF
    sngG = sngG * sngRGBF
    snbB = snbB * sngRGBF
  End If
  'Assign the character its color
  lngColor = RGB(sngR, sngG, snbB)
  On Error GoTo Err_Duplicate
  oCol.Add CStr(lngColor), CStr(lngColor)
  oChr.Font.Color = lngColor
Next oChr
Application.ScreenUpdating = True
Exit Sub
Err_Duplicate:
  Resume Dup_Reentry
  Beep
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #8  
Old 03-27-2013, 02:45 PM
macropod's Avatar
macropod macropod is offline every letter different color Windows 7 64bit every letter different color Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi Greg,

Good point about For Each. I should have though of that.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #9  
Old 03-28-2013, 04:16 AM
gmaxey gmaxey is offline every letter different color Windows 7 32bit every letter different color Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,421
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

I can't address the girlfriends computer, but here using the revised code above a single page of solid text (3588 characters) takes about 3 seconds.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
every letter different color first letter moves to far right tira Word 2 01-18-2013 12:33 PM
every letter different color Formatting a letter Ceri Word 1 05-03-2012 02:28 AM
every letter different color Business letter MK_Huef Word 1 03-27-2012 03:27 AM
Auto Letter Hannes Word 1 10-29-2009 06:27 AM
Letter Templates happymouth Word 8 05-17-2009 02:43 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:36 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft