如何使用VBA从Excel中的条件格式获取背景颜色 [英] How to get the background color from a Conditional Formatting in Excel using VBA

查看:1399
本文介绍了如何使用VBA从Excel中的条件格式获取背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在VBA脚本中获取使用Excel中的条件格式化规则分配的单元格背景颜色。我意识到使用 Range.Interior.Color 属性没有从Excel中应用的条件格式化功能导致的颜色。


$ b $我做了一些研究,我发现这很长的路要走 here ,它编译并运行但我没有得到分配的颜色[我总是(255,255,255)]



我正在使用Excel 2016,我想知道是否有一个更简单的方法使用一些内置的VBA功能或使用任何其他excel技巧获取此信息。

解决方案

如果您想知道使用条件格式规则(CFR)已着色的单元格,然后使用.Range.DisplayFormat.Interior.Color¹。



如果你想要明确知道一个CFR可能或可能没有被着色的单元格颜色,您需要迭代可能影响该单元格的CFR,并查看在每个.Range.FormatConditions( x )。Interior.Color。



¹注意:.DisplayFormat不可用工作表UDF。


I would like to obtain the cell background color assigned using a conditional formatting rule in Excel in my VBA script. I realized that using Range.Interior.Color property doesn't have the color resulting of an applied conditional formatting feature from Excel.

I did some research and I found this long way here, it compiles and runs but I don't get the assigned color [I get always (255,255,255)]

I am using Excel 2016 and I am wondering if there is a simpler way to obtain this information using some built-in VBA function or using any other excel trick.

解决方案

If you want to know the color of a cell that has been colored by a conditional formatting rule (CFR) then use .Range.DisplayFormat.Interior.Color¹.

If you want to definitively know what color a cell may or may not have been colored by a CFR you need to iterate through the CFRs that could be affecting that cell and look at each of the .Range.FormatConditions(x).Interior.Color.

¹ Note: .DisplayFormat is not available for a worksheet UDF.

这篇关于如何使用VBA从Excel中的条件格式获取背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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