Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-05-2012, 09:15 AM
Jennifer Murphy's Avatar
Jennifer Murphy Jennifer Murphy is offline Is there no wdOrange colorindex variable? Windows XP Is there no wdOrange colorindex variable? Office 2007
Competent Performer
Is there no wdOrange colorindex variable?
 
Join Date: Aug 2011
Location: Silicon Valley
Posts: 234
Jennifer Murphy is on a distinguished road
Default Is there no wdOrange colorindex variable?

I found a list of built-in color index variables here:

http://msdn.microsoft.com/en-us/libr...ffice.11).aspx

I don't see one for orange. Is there one? If not, can I define one myself?
Reply With Quote
  #2  
Old 11-05-2012, 01:40 PM
macropod's Avatar
macropod macropod is offline Is there no wdOrange colorindex variable? Windows 7 64bit Is there no wdOrange colorindex variable? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,387
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 Jennifer,

What you see is what you get and it's not extensible. You can, of course, work with the RGB equivalents.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 11-06-2012, 02:27 PM
gmaxey gmaxey is offline Is there no wdOrange colorindex variable? Windows 7 32bit Is there no wdOrange colorindex variable? Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,601
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Jennfifer,

For more on RGB and orange see: http://simple.wikipedia.org/wiki/Orange

HTML Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oShp As Word.Shape
Set oShp = ActiveDocument.Shapes.AddShape(1, 50, 30, 50, 50)
oShp.Fill.ForeColor.RGB = RGB(255, 160, 0)
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #4  
Old 12-03-2012, 07:55 PM
macropod's Avatar
macropod macropod is offline Is there no wdOrange colorindex variable? Windows 7 64bit Is there no wdOrange colorindex variable? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,387
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

Another approach, which returns the same colour as Greg's macro, is to define your own wdOrange value:
Dim wdOrange As Long
wdOrange = 41215
Thus:
Code:
Sub ScratchMacro()
Dim oShp As Word.Shape, wdOrange As Long
wdOrange = 41215
Set oShp = ActiveDocument.Shapes.AddShape(1, 50, 30, 50, 50)
oShp.Fill.ForeColor.RGB = wdOrange
End Sub
Do note that this approach doesn't add 'wdOrange' to the built-in color index variables, but at least you have a meaningful name you can work with.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 12-30-2012, 09:33 AM
Jennifer Murphy's Avatar
Jennifer Murphy Jennifer Murphy is offline Is there no wdOrange colorindex variable? Windows XP Is there no wdOrange colorindex variable? Office 2007
Competent Performer
Is there no wdOrange colorindex variable?
 
Join Date: Aug 2011
Location: Silicon Valley
Posts: 234
Jennifer Murphy is on a distinguished road
Default

Paul,

Thanks for the suggestion, but I can't get it to work.

Here's my little macro:
Code:
Sub MyRandCharColors()
 
Dim obChar As Range
Dim ilColorNext As Word.WdColorIndex
Dim wdOrange As Long
wdOrange = 41215
Dim vaColors
vaColors = Array(wdBlack, wdRed, wdBlue)
'vaColors = Array(wdBlack, wdOrange)
Dim nsRnd As Single
 
Randomize
For Each obChar In Selection.Characters
  nsRnd = Rnd()
  ilColorNext = vaColors(Int((UBound(vaColors) + 1) * nsRnd))
  obChar.Font.ColorIndex = ilColorNext
Next obChar
 
End Sub
As shown above, it works with the built-in colors. If I remove the comment from the second vaColors statement, it gets Run-time error "5843" indicating that one of the values is out of range.
Reply With Quote
  #6  
Old 12-30-2012, 09:55 AM
gmaxey gmaxey is offline Is there no wdOrange colorindex variable? Windows 7 32bit Is there no wdOrange colorindex variable? Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,601
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Jennifer,

wdOrange is a Long variable not a wdColorIndex:

Code:
Sub MyRandCharColors()
Dim oChr As Range
Dim sngRan As Single
Dim lngColorNext As Long
Dim wdOrange As Long
Dim varColors
wdOrange = 41215
varColors = Array(wdGreen, wdOrange, wdBlue)
Randomize
For Each oChr In Selection.Characters
  sngRan = Rnd()
  lngColorNext = varColors(Int((UBound(varColors) + 1) * sngRan))
  On Error Resume Next
  oChr.Font.ColorIndex = lngColorNext
  If Err.Number <> 0 Then
    oChr.Font.Color = lngColorNext
  End If
Next oChr
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #7  
Old 12-30-2012, 03:21 PM
macropod's Avatar
macropod macropod is offline Is there no wdOrange colorindex variable? Windows 7 64bit Is there no wdOrange colorindex variable? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,387
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

Jennifer,

Defining wdOrange as a Long variable doesn't make it part of the wdColorIndex collection. As I said in my previous post:
Quote:
Do note that this approach doesn't add 'wdOrange' to the built-in color index variables
You can refer to it via its name or value only, as shown in the code Greg and I posted.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #8  
Old 01-03-2013, 09:55 AM
Jennifer Murphy's Avatar
Jennifer Murphy Jennifer Murphy is offline Is there no wdOrange colorindex variable? Windows XP Is there no wdOrange colorindex variable? Office 2007
Competent Performer
Is there no wdOrange colorindex variable?
 
Join Date: Aug 2011
Location: Silicon Valley
Posts: 234
Jennifer Murphy is on a distinguished road
Default

Using the help from this thread, I added a new feature to my random color macro. The code snippet below will assign a random color from the entire color palette (16M colors) to each character in the selection. The result is kinda cool.

Code:
Sub MyRandCharColors()
Dim oChr As Range
Dim lngR As Long, lngG As Long, lngB As Long
Randomize
For Each oChr In Selection.Characters
  lngR = Rnd() * 256
  lngG = Rnd() * 256
  lngB = Rnd() * 256
  oChr.Font.Color = RGB(lngR, lngG, lngB)
Next oChr
End Sub
Replacing the last statement with this one will assign each letter a random shade of grey. Not sure it's useful.

Code:
oChr.Font.Color = RGB(lngR, lngR, lngR)  '256 shades of grey
I do have some questions:

Should the Rnd() factor be 256 or 255? Rnd() returns a number on [0,1). That is, including 0, but not 1. If I use 255, I'll never get a 255 color value. Right?

Should I convert lngR et al to integers (int(lngR))? It seems to work as is.

Some of the colors this macro produces are too light. The next snippet makes an adjustment if the sum of the color values exceed some threshold. This seems to work pretty well.

Code:
Sub MyRandCharColors()
Dim oChr As Range
Dim lngR As Long, lngG As Long, lngB As Long
Dim lngRGBSum As Long, lngRGBF As Long
Const lngRGBMax As Long = 500
Randomize
For Each oChr In Selection.Characters
  lngR = Rnd() * 256
  lngG = Rnd() * 256
  lngB = Rnd() * 256
  lngRGBSum = lngR + lngG + lngB
  If lngRGBSum > lngRGBMax Then     'If sum > max, scale it down to max
    lngRGBF = lngRGBMax / lngRGBSum
    lngR = lngR * lngRGBF
    lngG = lngG * lngRGBF
    lngB = lngB * lngRGBF
  End If
  oChr.Font.Color = RGB(lngR, lngG, lngB)
Next oChr
End Sub
Any comments or suggestions?
Reply With Quote
  #9  
Old 01-04-2013, 06:03 AM
gmaxey gmaxey is offline Is there no wdOrange colorindex variable? Windows 7 32bit Is there no wdOrange colorindex variable? Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,601
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Jennifer,

You will eventually get a 255 if you use 255. Try this:

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim i As Long
Dim lngRandom As Long
Do
  i = i + 1
  lngRandom = CLng(Rnd() * 255)
  If lngRandom = 255 Then
    MsgBox "Bingo!  In " & i & " loops you reached max value."
    Exit Do
  End If
Loop
End Sub
Personally, I don't think it matters that much if you use an integer or long variable.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #10  
Old 01-04-2013, 06:20 PM
Jennifer Murphy's Avatar
Jennifer Murphy Jennifer Murphy is offline Is there no wdOrange colorindex variable? Windows XP Is there no wdOrange colorindex variable? Office 2007
Competent Performer
Is there no wdOrange colorindex variable?
 
Join Date: Aug 2011
Location: Silicon Valley
Posts: 234
Jennifer Murphy is on a distinguished road
Default

Your code gets 255 because it rounds the real number, rather than truncating it. Rnd returns a real number on [0,1). It can return 0, but it cannot return 1. Multiplying that by 255 converts it to a real number on [0,255). It can be zero, but it cannot be 255. However, it can be 254.999, which your statement rounds to 255.

The problem with this is that the 256 possible integers do not have the same probability. Try this code:

Code:
Sub TestRnd()
Dim lngCounter(6) As Long
Dim i As Long
Dim sngRnd As Single, lngRnd As Long
For i = 1 To 10000
  sngRnd = Rnd() * 5    'Get random real number on [0,5)
  lngRnd = sngRnd       'Round it [0,5] 0 & 5 get half weight
  lngRnd = Int(sngRnd)  'Truncate it [0,4] All numbers get full weight
  lngCounter(lngRnd) = lngCounter(lngRnd) + 1
Next i
i = 0
End Sub
I don't know how to display an array, so I put a breakpoint on the last statement and put the array in the watch window. With your code, 0 and 255 each get half as many hits as 1-254. This is because 0.0-0.5 gets rounded to 0, 254.5-245.999 gets rounded to 255. That's only one half. The rest get rounded from -0.5 to +0.5.

With the code above, all 5 values get roughly equal tallies.

As it turns out, the font.color statement

Code:
oChr.Font.Color = RGB(sngR, sngG, sngB)
will accept floating point or fixed. Floating point are rounded. It will also accept values out of range. It converts those to 255.

Your post pointed out some other bugs in my code. I'll post a new version shortly.
Reply With Quote
  #11  
Old 01-05-2013, 12:18 AM
Jennifer Murphy's Avatar
Jennifer Murphy Jennifer Murphy is offline Is there no wdOrange colorindex variable? Windows XP Is there no wdOrange colorindex variable? Office 2007
Competent Performer
Is there no wdOrange colorindex variable?
 
Join Date: Aug 2011
Location: Silicon Valley
Posts: 234
Jennifer Murphy is on a distinguished road
Default

OK. I think I have all of the bugs out. Here's the new code:

Code:
Sub MyRandCharColors16M()
Dim oChr As Range

'Use floating point so scaling will work.
'Font.Color will take floating point, but it rounds,
'which messes up the probabilities.
Dim sngR As Single, sngG As Single, sngb As Single
Dim sngRGBSum As Single, sngRGBF As Single

'Define the maximum RGB sum.
'A score around 500-600 seems to give the best results.
'See Random color macro test data.pdf.
Const sngRGBMax As Single = 550
Randomize

'Loop thru characters in selection one at a time.
For Each oChr In Selection.Characters
  sngR = Int(Rnd() * 256) 'Select an integer on [0,255]
  sngG = Int(Rnd() * 256) 'Int is required for equal probability
  sngb = Int(Rnd() * 256) 'Else 0 only gets 0.5 and 255 gets 1.5
  'If the sum > max, scale all three back proportionately
  sngRGBSum = sngR + sngG + sngb
  If sngRGBSum > sngRGBMax Then     'If sum > max, scale it down to max
    sngRGBF = sngRGBMax / sngRGBSum
    sngR = sngR * sngRGBF
    sngG = sngG * sngRGBF
    sngb = sngb * sngRGBF
  End If
  'Assign the next character its color
  oChr.Font.Color = RGB(sngR, sngG, sngb)
Next oChr

End Sub
This seems to work quite well. The darkness can be controlled to some extent with the RGBMax variable. I uploaded a PDF document with sample output here:

https://www.dropbox.com/sh/zm8we5ssjtf13fp/9vR8Pms7uO?m

Someone on the sci.math newsgroup suggested that HSV color space would offer better color controls.

Here's a link. I haven't had time to check it out.

http://en.wikipedia.org/wiki/HSL_and_HSV

If the same color value is used for all three RGB settings, we get shades of grey.

Code:
Sub MyRandCharColors256G()
Dim oChr As Range
Dim sngGrey As Single
Randomize
For Each oChr In Selection.Characters
'  sngGrey = Int(Rnd() * 256) '256 shades of grey
  sngGrey = Int(Rnd() * 192) '192 shades of grey
'  sngGrey = Int(Rnd() * 128) '128 shades of grey
  oChr.Font.Color = RGB(sngGrey, sngGrey, sngGrey)
Next oChr
End Sub
Thanks for all the help.
Reply With Quote
  #12  
Old 01-05-2013, 07:15 AM
gmaxey gmaxey is offline Is there no wdOrange colorindex variable? Windows 7 32bit Is there no wdOrange colorindex variable? Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,601
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Jennifer,

Thanks. Only comment is that Word 2003 seems to want to take its ball and go home after about 5000 characters. After that point no more characters are modified and UI events like (change font color) are frozen until the document is saved and reopened.

I don't have time or interest in trying to figure out why or if anything can be done about it, just thowing it out for info.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #13  
Old 01-05-2013, 09:54 AM
Jennifer Murphy's Avatar
Jennifer Murphy Jennifer Murphy is offline Is there no wdOrange colorindex variable? Windows XP Is there no wdOrange colorindex variable? Office 2007
Competent Performer
Is there no wdOrange colorindex variable?
 
Join Date: Aug 2011
Location: Silicon Valley
Posts: 234
Jennifer Murphy is on a distinguished road
Default

Word 2007 does not appear to have that problem up to at least 100,000 characters. But there are some other side effects:
  1. It took the macro 50 seconds to re-color all 100,000 characters.
  2. The file grew from 22KB to 818KB.
  3. It takes Word a very long time (up to 20-30 minutes) to complete the tallies for the status bar (lines, paragraphs, pages, sections, characters). The same document with all of the characters set to "automatic" (black) completes the tallies in seconds. Curiously, if I load the all-black document, wait for the tallies to complete, then run the macro, the tallies appear to start over from scratch even though no characters were added or deleted.
  4. The little Word Count pop-up formats the totals wrong if they exceed 5 digits (see attached image). 100,000 is displayed as "100,00".
sigh
Attached Images
File Type: jpg Word 20130105 Word count number formatting error.jpg (59.3 KB, 31 views)
Reply With Quote
  #14  
Old 01-05-2013, 10:04 AM
gmaxey gmaxey is offline Is there no wdOrange colorindex variable? Windows 7 32bit Is there no wdOrange colorindex variable? Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,601
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Jennifer,

I'm sorry, I had checked with Word 2003, 2007, 2010 and 2013 and forgot that that issue was not apparent in the other versions.

Unless MS does something in a Word2013 service pack then these type of process are going to be brutally slow (it current takes loops and for each process 3 to 4 time longer to run in Word 2013).

I think the file size issue is because all the color attributes have to be written in the OpenOfficeXMLFile format file.

Never notices the character count display issue before.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #15  
Old 01-05-2013, 10:11 AM
Jennifer Murphy's Avatar
Jennifer Murphy Jennifer Murphy is offline Is there no wdOrange colorindex variable? Windows XP Is there no wdOrange colorindex variable? Office 2007
Competent Performer
Is there no wdOrange colorindex variable?
 
Join Date: Aug 2011
Location: Silicon Valley
Posts: 234
Jennifer Murphy is on a distinguished road
Default

The slowness is not an issue for me. I only use this macro to create special effects on cards and envelopes for the grandkids. So it's usually only a title or a few paragraphs.

The macro has been fun to work on. I have a few more tweaks. If I like it, I'll post the complete macro.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there no wdOrange colorindex variable? Run-time error '91': Object variable or With block variable not set tinfanide Excel Programming 2 06-10-2012 10:17 AM
Is there no wdOrange colorindex variable? variable Page references scrinmemphis Word 4 06-06-2012 11:50 PM
Is there no wdOrange colorindex variable? Capture a Font in a Variable joatmon Excel Programming 1 05-30-2012 08:23 PM
Help with VBA macro - Variable input sc30317 Excel Programming 0 08-31-2011 01:00 PM
Variable fields? Emalee77 PowerPoint 0 01-30-2011 05:58 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:38 PM.


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