如何在 Excel/VBA 中获取 RGB 颜色的相应十六进制值? [英] How do I get the corresponding Hex value of an RGB color in Excel/VBA?
问题描述
我试图在我的 VBA 代码中设置一个颜色的公共常量.通常,我可以使用:
I'm trying to set a public const of a color in my VBA code. Normally, I can use:
Dim BLUE As Long
BLUE = RGB(183, 222, 232)
但是,由于 RGB 功能,无法公开 const .我使用在线转换器将此 RGB 值转换为十六进制,然后返回 B7DEE8
However, there's no way to public const that because of the RGB function. I converted this RGB value to Hex using an online converter, and I got back B7DEE8
使用:
BLUE = &HB7DEE8
导致完全不同的颜色.我认为这实际上可能是一种 RGBA 颜色,我试过 B7DEE8__ 并且颜色非常接近(最后一位数字是 B8),但我想知道如何实际找到正确的值.
results in a completely different color. I think this may actually be an RGBA color, and I've tried B7DEE8__ and got the color pretty close (with the last digit being B8), but I'd like to know how to actually find the correct value.
注意:我真的不需要代码将其转换为十六进制,我只需要知道如何找到它,因为我在 Excel 工作表上使用了五种恒定颜色,我想设置它们.
Note: I don't really need code to convert this to hex, I just need to know how to find it, because I have five constant colors I use on my Excel sheet, and I'd like to set them up.
推荐答案
您必须将字节反转为顺序
You'll have to reverse the bytes into order
BLUE = &HE8DEB7
获得正确的颜色值.
这篇关于如何在 Excel/VBA 中获取 RGB 颜色的相应十六进制值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!