View Single Post
 
Old 10-30-2013, 07:20 AM
gmaxey gmaxey is offline Windows 7 32bit Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

That number doesn't have to be 7 or 8 digits. It can be three and it represents a long data type.

Experiment with this in a new document:

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
ActiveDocument.Range.Text = "ABC...XYZ"
'Assign color using constants.
ActiveDocument.Range.Characters(1).Font.Color = wdColorRed
ActiveDocument.Range.Characters(2).Font.Color = wdColorGreen
ActiveDocument.Range.Characters(3).Font.Color = wdColorBlue
'Color property returns a long data type
Debug.Print ActiveDocument.Range.Characters(1).Font.Color
Debug.Print ActiveDocument.Range.Characters(2).Font.Color
Debug.Print ActiveDocument.Range.Characters(3).Font.Color
'Assign color using long values.
ActiveDocument.Range.Characters(4).Font.Color = 255
ActiveDocument.Range.Characters(5).Font.Color = 32768
ActiveDocument.Range.Characters(6).Font.Color = 16711680
'What are the RGB values?
Debug.Print fcnLongToRGB(255) 'Red
'Green has a long value 32768
Debug.Print fcnLongToRGB(32768) 'Green
'Blue as a long value 16711680
Debug.Print fcnLongToRGB(16711680) 'Blue
'Assign color using RGB values
ActiveDocument.Range.Characters(7).Font.Color = RGB(255, 0, 0)
ActiveDocument.Range.Characters(8).Font.Color = RGB(0, 128, 0)
ActiveDocument.Range.Characters(9).Font.Color = RGB(0, 0, 255)
End Sub
Code:
Function fcnLongToRGB(ByRef lngColor As Long) As String
Dim lngRed As Long, lngGreen As Long, lngBlue As Long
lngRed = lngColor Mod 256
lngGreen = (lngColor \ 256) Mod 256
lngBlue = (lngColor \ 256 \ 256) Mod 256
fcnLongToRGB = "RGB(" & lngRed & "," & lngGreen & "," & lngBlue & ")"
End Function
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote