vba Excel 2010 - 单元格和形状着色 - 我的想法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7847128/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 14:19:23  来源:igfitidea点击:

Excel 2010 - Cell and Shapes Coloring - My ideas

excelvbacolors

提问by ihightower

Excel 2003 had a simple ...interior.colorindex and only 56 numbers. But, this is changed with Excel 2010 for better control.

Excel 2003 有一个简单的 ...interior.colorindex 并且只有 56 个数字。但是,为了更好的控制,Excel 2010 改变了这一点。

Now while developing a program.. which is supposed to copy a cell color (in VBA) and put the same color of the cell to an Excel Shape depending on the cell contents... i was lost with several different objects like this:

现在在开发一个程序时......它应该复制一个单元格颜色(在VBA中)并根据单元格内容将单元格的相同颜色放入Excel形状......我迷失了几个不同的对象,如下所示:

For the Cell:

对于细胞:

Sheets("Config").Range("E1").Interior.ThemeColor = 10
Sheets("Config").Range("E1").Interior.TintAndShade = -0.249977111117893 

For the Shape:

对于形状:

Activesheet.shapes("R3").fill.forecolor.objectthemecolor = 7
Activesheet.shapes("R3").fill.forecolor.brightness = 0.6
Activesheet.shapes("R3").fill.forecolor.schemecolor = 42
Activesheet.shapes("R3").fill.forecolor.tintandshade (and this doesn't even work)

采纳答案by Flexo

I have found a better simpler way which don't require all the above different naming..

我找到了一种更好的更简单的方法,它不需要上述所有不同的命名。

All you need is:

所有你需要的是:

range("b9").Interior.Color

which will return a long... like this for example: 682978 (of the hex color in decimal)

这将返回一个长...像这样例如:682978(十进制的十六进制颜色)

And, you can set the color for the shape like this:

而且,您可以像这样设置形状的颜色:

.Shapes(xName).Fill.ForeColor.RGB = 682978 (some variable)

Other useful notes are:

其他有用的注释是:

range("h1").Interior.Color = rgb(0,123,124) 

and, for printing in console

并且,用于在控制台中打印

? rgb(0, 123, 124)