vba 格式条件和内部颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12689750/
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
FormatConditions and Interior Color
提问by assylias
I have an old macro that was working fine on Excel 2003 but creates issues with Excel 2010. The part that causes problems is:
我有一个旧的宏,它在 Excel 2003 上运行良好,但在 Excel 2010 上产生了问题。导致问题的部分是:
If Not IsNull(someRange.FormatConditions(parActiveCondition).Interior.Color) Then
locVisibleColor = someRange.FormatConditions(parActiveCondition).Interior.Color
End if
where parActiveCondition
is the active conditional formatting number on someRange
.
上parActiveCondition
的活动条件格式编号在哪里someRange
。
When the background is selected as "No Color", someRange.FormatConditions(parActiveCondition).Interior.Color
returns
当背景选择为“无颜色”时,someRange.FormatConditions(parActiveCondition).Interior.Color
返回
Null
in Excel 2003- 0 in Excel 2010
Null
在 Excel 2003 中- 0 在 Excel 2010 中
The problem is that a black background also returns 0. So in Excel 2010 it seems no longer possible to make the difference between a black background and no background color.
问题是黑色背景也返回 0。所以在 Excel 2010 中似乎不再可能区分黑色背景和无背景颜色。
Does anybody know a workaround?
有人知道解决方法吗?
ps: I could obviously select a white background instead of "No Color" but I'd rather not change all the spreadsheets and conditional formatting rules.
ps:我显然可以选择白色背景而不是“无颜色”,但我不想更改所有电子表格和条件格式规则。
回答by brettdj
You could use a Boolean secondary check such as
您可以使用布尔辅助检查,例如
IsNull(someRange.FormatConditions(parActiveCondition).Interior.ColorIndex) 'or
IsNull(someRange.FormatConditions(parActiveCondition).Interior.TintAndShade)
when
什么时候
.FormatConditions(parActiveCondition).Interior.Color = 0
回答by Trace
Option Explicit
Sub test()
Dim Color
Dim R As Integer
Dim G As Integer
Dim B As Integer
Color = ThisWorkbook.Sheets(1).Range("A1").Interior.Color
R = Color Mod 256
G = (Color \ 256) Mod 256
B = (Color \ 256 \ 256) Mod 256
ThisWorkbook.Sheets(1).Range("B1").Interior.Color = RGB(R, G, B)
End Sub
Black returns (0,0,0)
It appears however that "no color" returns (255,255,255) (=white)
黑色返回 (0,0,0)
然而,似乎“无颜色”返回 (255,255,255)(=白色)