在对象属性中,可以设置例如格式化的自定义颜色。 &H00893959&。玩弄它似乎与RGB等有关,但我找不到太多的逻辑。有谁知道这些代码是如何工作的?
这很可能是三个颜色字节的十六进制表示。
&H
为前缀的数字是hexadecimal(又名Base 16)。&
为后缀的数字是unsigned integers。您会看到它更常见地表示为HTML颜色代码而没有额外的字符#893959
,这是下面的颜色。 (更多关于这种颜色here。):
这是一个VBA函数,用于提取3个颜色字节,并使用RGB Function从十六进制转换为十进制(用于Excel / VBA)。
Function Hex2RGB(hex As String) As Long
Dim r As Long, g As Long, b As Long
With Application.WorksheetFunction
r = .Hex2Dec(Mid(hex, 5, 2))
g = .Hex2Dec(Mid(hex, 7, 2))
b = .Hex2Dec(Mid(hex, 9, 2))
End With
Hex2RGB = RGB(r, g, b)
End Function
Sub Demo()
Const hexColor = "&H00893959&"
Debug.Print "The RBG (decimal) interpretation of '" _
& hexColor & "' is " & Hex2RGB(hexColor) & "." 'returns 5847433
End Sub