VBA Excel:Colorindex兼容性的RGB范围 [英] VBA Excel: Range of RGB for Colorindex compatibility

查看:567
本文介绍了VBA Excel:Colorindex兼容性的RGB范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Excel 2007中创建了一个宏,它允许值取决于源文件的字体颜色,如下所示(这段代码是循环的一部分):

 如果Worksheets(Source1)。Cells(i,j).Font.Color = RGB(165,165,165) Source1)。Cells(i,j).Font.Color = RGB(117,146,60)Then 
Worksheets(Result)。Cells(UnusedRow,15).Value =Closed
Else
工作表(Result)。Cells(UnusedRow,15).Value =Active
End If

这没有问题。



但是,奇怪的是,相同源文件中的相同单元格在打开时具有不同的RGB值使用Excel 2013 :2007年的RGB(165,165,165)在2013年变成RGB(166,166,166),并且2007年的RGB(117,146,60)变成RGB(118,147,60)在2013年。



这就是为什么我想为字体颜色中的每个数字使用一个小范围,例如对于RGB(x,y,z) file:

 如果x => 164且x <= 167且y = 164且y <= 167且z = 164 and z <= 167 Then 
...

有人可以告诉我如何代码这正确吗?谢谢!

解决方案

好吧,我的大脑终于找到了空气,我得到了答案。



而不是 Color ,请使用 ColorIndex 。这是他们在调色板中选择的颜色的位置的索引。



我不是说这是一个伟大的系统(不是),而是考虑到你的约束 - 依赖



我认为。


I have a macro created in Excel 2007 which lets a value depend on the font color of a source file, as follows (this piece of code is part of a loop):

 If Worksheets("Source1").Cells(i, j).Font.Color = RGB(165, 165, 165) Or Worksheets("Source1").Cells(i, j).Font.Color = RGB(117, 146, 60) Then
     Worksheets("Result").Cells(UnusedRow, 15).Value = "Closed"
 Else
     Worksheets("Result").Cells(UnusedRow, 15).Value = "Active"
 End If

This works without a problem.

However, strangely enough the same cells in the same source file have different RGB values when opened with Excel 2013: RGB(165, 165, 165) in 2007 becomes RGB(166, 166, 166) in 2013, and RGB(117, 146, 60) in 2007 becomes RGB(118, 147, 60) in 2013.

That is why I thought to use a small range for every number in the font color, for instance for RGB(x, y, z) from the source file:

 If x => 164 And x <= 167 And y => 164 And y <= 167 And z => 164 And z <= 167 Then 
   ...

Can someone tell me how to code this correctly? Thanks!

解决方案

Okay, my brain finally came up for air, and I've got an answer.

Instead of Color, use ColorIndex. That's the index of the position of the color they pick in the palette.

I'm not saying it's a great system (it's not) but given your constraint - relying on the user to click a certain color button, it's as good as you're going to get.

I think.

这篇关于VBA Excel:Colorindex兼容性的RGB范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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