Excel VBA宏彩色代码
问题描述:
我的程序根据输入自动突出显示(填充颜色)excel单元格。我记录了Excel宏以查找我想要的颜色代码(颜色的整数值;即白色16777215),并且我注意到黄色是65535,青色是16776960,尽管在现实生活中这两个值应该颠倒(黄色是16776960或ffff00在RGB中,青色是65535或RGB中的00ffff)Excel VBA宏彩色代码
请问有人可以解释这种行为吗?
感谢
答
也许这里就是答案: Why are Excel RGB values backwards?
我曾经前一段时间有同样的问题,所以我已经建立了这样的事情:
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
这是一个问题,需要一些'VBA'来回答,还是只是好奇? –
Windows最初是为小端架构(x86)编写的,后续版本的Windows仍与此兼容。在小端表示中,0xRRGGBB实际上将在内存中表示为BBGGRR。 –