2016-11-28 3 views
1

私のプログラムは、入力に基づいてExcelセルの色を自動的に強調表示します(色を塗りつぶします)。実際にはこれらの2つの値を逆にする必要がありますが、Excelマクロを記録して(私は色の整数値、つまり16777215は白)、黄色は65535、シアンは16776960です(黄色は16776960 RGBではffff00、RGBではシアンは65535または00ffff)Excel VBAマクロカラーコード

誰かがこの動作をしてください。私はこのような何かを構築しているので、私はいくつかの時間前に同じ問題があった Why are Excel RGB values backwards?

おかげ

おそらくここ
+0

はこの質問であること答えるにはいくつかの 'VBA'が必要ですか、それともあなただけは興味がありますか? –

+0

Windowsはもともとリトルエンディアンアーキテクチャ(x86)用に書かれたもので、Windowsの後続バージョンはこれと互換性があります。リトルエンディアン表現では、0xRRGGBBは実際にはBBGGRRとしてメモリ内に表現されます。 –

答えて

0

が答えです

Option Explicit 
'RGB2HTMLColor html htmlcolor 
'INPUT: Numeric (Base 10) Values for R, G, and B) 
'OUTPUT: 
'String to be used for color of element in VBA. 
'E.G -> if the color is like this:-> &H80000005& 
'we should change just the last 6 positions to get our color! H80 must stay. 

Public Function RGB2HTMLColor(B As Byte, G As Byte, R As Byte) As String 

    Dim HexR As Variant, HexB As Variant, HexG As Variant 
    Dim sTemp As String 

    On Error GoTo ErrorHandler 

    'R 
    HexR = Hex(R) 
    If Len(HexR) < 2 Then HexR = "0" & HexR 

    'Get Green Hex 
    HexG = Hex(G) 
    If Len(HexG) < 2 Then HexG = "0" & HexG 

    HexB = Hex(B) 
    If Len(HexB) < 2 Then HexB = "0" & HexB 

    RGB2HTMLColor = HexR & HexG & HexB 
    Debug.Print "Enter RGB, without caring for the real colors, the function knows what it is doing." 
    Debug.Print "IF 50D092 then &H0050D092&" 

    Exit Function 

ErrorHandler: 
    Debug.Print "RGB2HTMLColor was not successful" 
End Function