What is the RGB value of the colour of Excel's scroll bars

  • Thread starter Thread starter Charles Jordan
  • Start date Start date
C

Charles Jordan

Hi NG. We have surrounded an Excel scroll bar with cells coloured grey
(RGB(240,240,240) - but it's not a precise match. Does any on know the
RGB value of the scroll bars ?

Thanks Charles
 
It appears to be 236,233,216

I found this by putting a scrollbar on a userform and running the sub
test, which I've reproduced below in case you need to check other colours.

Private Declare Function TranslateColor Lib "olepro32.dll" _
Alias "OleTranslateColor" (ByVal clr As OLE_COLOR, _
ByVal palet As Long, col As Long) As Long

Sub test()
Dim RealColor As Long, test As OLE_COLOR
test = UserForm1.ScrollBar1.BackColor
TranslateColor test, 0, RealColor
MsgBox "The backcolor of this form is R=" & _
CStr(RealColor And &HFF&) & " G=" & _
CStr((RealColor And &HFF00&) / 2 ^ 8) & _
" B=" + CStr((RealColor And &HFF0000) / 2 ^ 16)
End Sub
 
Steve Garman said:
It appears to be 236,233,216

I found this by putting a scrollbar on a userform and running the sub
test, which I've reproduced below in case you need to check other colours.

Private Declare Function TranslateColor Lib "olepro32.dll" _
Alias "OleTranslateColor" (ByVal clr As OLE_COLOR, _
ByVal palet As Long, col As Long) As Long

Sub test()
Dim RealColor As Long, test As OLE_COLOR
test = UserForm1.ScrollBar1.BackColor
TranslateColor test, 0, RealColor
MsgBox "The backcolor of this form is R=" & _
CStr(RealColor And &HFF&) & " G=" & _
CStr((RealColor And &HFF00&) / 2 ^ 8) & _
" B=" + CStr((RealColor And &HFF0000) / 2 ^ 16)
End Sub


Thanks Steve - for accuracy, promptness, replying on a Sunday ..and a
very scientific solution. Charles
 
This code should work for any location on the screen:

Option Explicit

Private Declare Sub Sleep _
Lib "kernel32" _
(ByVal dwMilliseconds As Long)

Private Declare Function GetCursorPos _
Lib "user32" _
(lpPoint As POINTAPI) As Long

Private Declare Function GetPixel _
Lib "gdi32" _
(ByVal hdc As Long, _
ByVal x As Long, _
ByVal y As Long) As Long

Private Declare Function GetDC _
Lib "user32" _
(ByVal hwnd As Long) As Long

Private Type POINTAPI
x As Long
y As Long
End Type

Public Sub ColorUnderCursor()

Dim pCursorPos As POINTAPI
Dim lngColorUnderCursor As Long

Dim R As Long
Dim G As Long
Dim B As Long

' Sleep two seconds to allow cursor
' to move somewhere useful
Sleep 2000

GetCursorPos pCursorPos

lngColorUnderCursor = _
GetPixel(GetDC(0&), _
pCursorPos.x, pCursorPos.y)

SplitRGB lngColorUnderCursor, R, G, B

MsgBox CStr(lngColorUnderCursor) & _
":" & vbCrLf & _
"R=" & CStr(R) & vbCrLf & _
"G=" & CStr(G) & vbCrLf & _
"B=" & CStr(B)
End Sub

Sub SplitRGB( _
ByVal RGBValue As Long, _
ByRef R As Long, _
ByRef G As Long, _
ByRef B As Long _
)
R = RGBValue And 255
G = RGBValue \ 256 And 255
B = RGBValue \ 256 ^ 2 And 255
End Sub
 
This code should work for any location on the screen:

Option Explicit

Private Declare Sub Sleep _
Lib "kernel32" _
(ByVal dwMilliseconds As Long)

Private Declare Function GetCursorPos _
Lib "user32" _
(lpPoint As POINTAPI) As Long

Private Declare Function GetPixel _
Lib "gdi32" _
(ByVal hdc As Long, _
ByVal x As Long, _
ByVal y As Long) As Long

Private Declare Function GetDC _
Lib "user32" _
(ByVal hwnd As Long) As Long

Private Type POINTAPI
x As Long
y As Long
End Type

Public Sub ColorUnderCursor()

Dim pCursorPos As POINTAPI
Dim lngColorUnderCursor As Long

Dim R As Long
Dim G As Long
Dim B As Long

' Sleep two seconds to allow cursor
' to move somewhere useful
Sleep 2000

GetCursorPos pCursorPos

lngColorUnderCursor = _
GetPixel(GetDC(0&), _
pCursorPos.x, pCursorPos.y)

SplitRGB lngColorUnderCursor, R, G, B

MsgBox CStr(lngColorUnderCursor) & _
":" & vbCrLf & _
"R=" & CStr(R) & vbCrLf & _
"G=" & CStr(G) & vbCrLf & _
"B=" & CStr(B)
End Sub

Sub SplitRGB( _
ByVal RGBValue As Long, _
ByRef R As Long, _
ByRef G As Long, _
ByRef B As Long _
)
R = RGBValue And 255
G = RGBValue \ 256 And 255
B = RGBValue \ 256 ^ 2 And 255
End Sub

Hi OneDay. Thanks, but since I'm not a Windows programmer, could you
tell us whether your magnificent code will run with Excel 95 - our
lowest common denominator ? (And still the chosen development platform
since it is *so much* faster to develop in, in our view, than Excel 97
and up, *even after* porting to Excel 2004 which we do all the time).
Charles
 
(e-mail address removed) wrote ...
Hi OneDay. Thanks, but since I'm not a Windows programmer, could you
tell us whether your magnificent code will run with Excel 95 - our
lowest common denominator ?

It does for Excel95 on WinXP, subject to replacing 'vbCrLf' with
'Chr$(10)'. Who said it was my code? I recognize SplitRGB as being
from Chip Pearson's site.
(Excel95 is) still the chosen development platform
since it is *so much* faster to develop in, in our view, than Excel 97
and up, *even after* porting to Excel 2004 which we do all the time

A smell of petroleum prevails throughout, right?

--
 
(e-mail address removed) wrote ...


It does for Excel95 on WinXP, subject to replacing 'vbCrLf' with
'Chr$(10)'. Who said it was my code? I recognize SplitRGB as being
from Chip Pearson's site.


A smell of petroleum prevails throughout, right?

--

Thanks OneDay - yess, we're knee deep in it> Slows down my code a bit ! Tks C.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top