G
Greg Maxey
With the extensive help of Jay Freedman and Jonathan West, I am
beginning to understand color in Word. I have put together a macro for
extracting the Long and RBG value of a color selected in the
Format>Borders and Shading>Shading dialog. I have one problem. For
some odd reason there is an extra space in the second message box
dispaly:
oColorRBG = Str$(rVal) & ", " & Str$(gVal) & ", " & Str$(bVal)
MsgBox "Color long value: " & oColorLng
MsgBox "Color RBG value: (" & oColorRBG & ")"
For "Red" is should dispay: Color RBG value: (255, 0, 0) but it is
coming out
Color RBG value: ( 255, 0, 0)
I can't figure out how to close up the space between the ( and 255.
I realize that this is a minor nit, but would like to figure it out
just the same. Thanks.
Here is the complete code:
Sub QuickAndEasyColorData()
Dim oDoc As Word.Document
Dim oRng As Word.Range
Set oDoc = Documents.Add
Set oRng = oDoc.Range
Dim oColorLng As Long
Dim rVal As Long
Dim gVal As Long
Dim bVal As Long
Dim oColorRBG As String
oRng.InsertAfter "Sample Text"
oRng.MoveEnd wdCharacter, -1
Application.ScreenRefresh
oRng.Select
With Dialogs(wdDialogFormatBordersAndShading)
If .Show = -1 Then
.Execute
Application.ScreenRefresh
oColorLng = oRng.Shading.BackgroundPatternColor
rVal = oColorLng Mod 256
bVal = Int(oColorLng / 65536)
gVal = Int((oColorLng - (bVal * 65536) - rVal) / 256)
oColorRBG = Str$(rVal) & ", " & Str$(gVal) & ", " & Str$(bVal)
MsgBox "Color long value: " & oColorLng
MsgBox "Color RBG value: (" & oColorRBG & ")"
End If
End With
oDoc.Close wdDoNotSaveChanges
End Sub
beginning to understand color in Word. I have put together a macro for
extracting the Long and RBG value of a color selected in the
Format>Borders and Shading>Shading dialog. I have one problem. For
some odd reason there is an extra space in the second message box
dispaly:
oColorRBG = Str$(rVal) & ", " & Str$(gVal) & ", " & Str$(bVal)
MsgBox "Color long value: " & oColorLng
MsgBox "Color RBG value: (" & oColorRBG & ")"
For "Red" is should dispay: Color RBG value: (255, 0, 0) but it is
coming out
Color RBG value: ( 255, 0, 0)
I can't figure out how to close up the space between the ( and 255.
I realize that this is a minor nit, but would like to figure it out
just the same. Thanks.
Here is the complete code:
Sub QuickAndEasyColorData()
Dim oDoc As Word.Document
Dim oRng As Word.Range
Set oDoc = Documents.Add
Set oRng = oDoc.Range
Dim oColorLng As Long
Dim rVal As Long
Dim gVal As Long
Dim bVal As Long
Dim oColorRBG As String
oRng.InsertAfter "Sample Text"
oRng.MoveEnd wdCharacter, -1
Application.ScreenRefresh
oRng.Select
With Dialogs(wdDialogFormatBordersAndShading)
If .Show = -1 Then
.Execute
Application.ScreenRefresh
oColorLng = oRng.Shading.BackgroundPatternColor
rVal = oColorLng Mod 256
bVal = Int(oColorLng / 65536)
gVal = Int((oColorLng - (bVal * 65536) - rVal) / 256)
oColorRBG = Str$(rVal) & ", " & Str$(gVal) & ", " & Str$(bVal)
MsgBox "Color long value: " & oColorLng
MsgBox "Color RBG value: (" & oColorRBG & ")"
End If
End With
oDoc.Close wdDoNotSaveChanges
End Sub