Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA colour numbers to hexidecimal/RGB Values 1

Status
Not open for further replies.

NIA2

Technical User
Aug 30, 2006
137
AU
Hi All,

I've inserted an image into a userform in Word but it's appearing very jagged. I tried two different file formats - .wmf and .gif, both with same problem.

I wanted to try and add a matt colour to the edges of the graphic (via photoshop), the same colour as the background colour of the form, but I noticed that the colour numbers in the VBA editor aren't one that I recognise, eg.

&H000080FF&

Can someone tell me how I can get the hexidecimal or RGB equivalent value of the above colour?

Thanks for any help offered.
 
I thinkt he system colours can change , depending on the users set up, so whats &H000080FF& on your machine might not be the same colour as what is on mine.

why dont you take a screen shot, open it up in photoshop and use the colour picker to find the rgb ?

Chance,

F, G + yeah reached 50
 
Thanks - great idea. Worked perfectly
 
>&H000080FF&

Oh, I think that might be the same colour most machines ...

But what I suspect you meant was something like:

&H8000000F&

Which is also known as vbButtonFace, i.e. it is a reference to the colour currently defined by your desktop theme for the face of a button - and it could indeed be different on different machines.

Now obviously Windows can somehow translate this special color index into the correct RGB value - and thus we should be able to as well. And we can, using an API call call OLETranslateColor (since the index is actually an OLE Color). Here's an example (which uses a bit of a shortcut to get the RGB components back individually rather a more normal technique of getting the full hex value back and then using masking to extract the RGB values). In addition we use the more interesting vbActiveTitleBar OLE Color:
Code:
[blue]Option Explicit
Private Declare Function OleTranslateColor Lib "OLEPRO32.DLL" (ByVal OLE_COLOR As Long, ByVal HPALETTE As Long, pccolorref As Any) As Long
Private Const CLR_INVALID = -1

Private Type RGB
    Red As Byte
    Green As Byte
    Blue As Byte
End Type

Private Sub Example()
    Dim TranslateColor As RGB
    
    OleTranslateColor vbActiveTitleBar, 0&, TranslateColor ' &H80000002&
    With TranslateColor
        Debug.Print RGB(.Red, .Green, .Blue)
    End With
End Sub[/blue]



 
Thanks – will try it out
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top