Gremlin space in string data

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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

.



Relevant Pages

  • RE: An Array of Values
    ... I create one sample code for you concerning how to insert the data into the word doc file. ... Dim oApp As New Word.Application ... Dim oRng As Word.Range ... Set oDoc = oApp.Documents.Add ...
    (microsoft.public.office.developer.automation)
  • Re: Gremlin space in string data
    ... The Str$() is a very old part of BASIC, and dates back to the days of teletype machines, where you would want the same number of characters to be used for printing a number irrespective of whether it was positive or negative. ... CStrdoesn't include a leading space in the string it produces. ... Dim oDoc As Word.Document ... Dim oColorLng As Long ...
    (microsoft.public.word.vba.general)
  • Re: RGB Codes for 90% Black
    ... Dim oRng As Word.Range ... Dim oColorLng As Long ... Word MVP web site http://word.mvps.org ...
    (microsoft.public.word.docmanagement)
  • Re: One more question
    ... Dim oRng As Word.Range ... Dim oRngDup As Word.Range ... insert the break or the paragraph. ...
    (microsoft.public.word.vba.general)
  • Re: Update Graph via VBA - Changes Not Saved
    ... Dim oMSGraphWrapper As Word.InlineShape ... Set oDoc = ActiveDocument ... Set oMSGraphWrapper = Selection.InlineShapes ... Dim intA As Integer, intB As Integer ...
    (microsoft.public.word.vba.general)