Excel VBA 上的坏和好亮点的颜色代码是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22380829/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What's the color code of Bad and Good Highlights on Excel VBA?
提问by Iancovici
I tried searching on goggle but couldn't figure out a good keyword to find it. Anyone knows what color code I need to use on Excel VBA to get this?
我尝试在护目镜上搜索,但找不到合适的关键字来找到它。任何人都知道我需要在 Excel VBA 上使用什么颜色代码才能得到这个?
回答by Dmitry Pavliv
So macro recorder gives you this code:
所以宏记录器给你这个代码:
Sub Macro2()
Range("A1").Select
Selection.Style = "Good"
Range("B1").Select
Selection.Style = "Bad"
End Sub
Next step is to get color:
下一步是获取颜色:
MsgBox Range("A1").Interior.Color ' returns 13561798
MsgBox Range("B1").Interior.Color ' returns 13551615
and finally, when you know color you can do this:
最后,当你知道颜色时,你可以这样做:
Range("A1:A10").Interior.Color = 13561798 ' for Good style
Range("B1:B10").Interior.Color = 13551615 ' for Bad style
回答by IanD
Alternatively if you want to use the Good or Bad styles you could simply use the style property of the range object i.e.
或者,如果您想使用 Good 或 Bad 样式,您可以简单地使用 range 对象的 style 属性,即
Range("A1").Style = "Good" Range("B1").Style = "Bad"
Range("A1").Style = "Good" Range("B1").Style = "Bad"