如何在Excel / VBA中获取RGB颜色的相应十六进制值? [英] How do I get the corresponding Hex value of an RGB color in Excel/VBA?

查看:2635
本文介绍了如何在Excel / VBA中获取RGB颜色的相应十六进制值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的VBA代码中设置一个颜色的公共const。通常,我可以使用:

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)

但是,没有办法让public const因为RGB函数。我使用在线转换器将这个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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆