ActiveDocument.Tables(k).Range.Cells(j).Shading.BackgroundPatternColor 返回 -1
我有一个包含很多表格的 Word 2007 文档。每个表格都有某些单元格,其中填充了 2 种自定义颜色。我创建了一个宏,它需要输入 3 个值来提供 RGB 函数,创建一种颜色,将其与每种颜色进行匹配,然后使用新颜色更改匹配。
我使用了一个 If
语句,将填充单元格的颜色与 RGB 函数返回的颜色进行比较,并向该函数提供用户给出的输入。
If ActiveDocument.Tables(k).Range.Cells(j).Shading.BackgroundPatternColor = RGB(inputRed, inputGreen, inputBlue) Then
'code
end if
当我浏览文档查看结果时,我注意到 3 个表中的一些单元格保留了旧颜色,因此显然宏无法识别它。
在 Word 2007 中,我选择了应该更改颜色的单元格。我去了家 ->阴影->更多颜色->自定义并看到 3 个值与用户输入的 3 个值完美匹配。
盯着显示器三十分钟后,我想到去看医生检查一下我的眼睛。 :)
在这样做之前,我开始调试该应用程序。在每个未更改的单元格上。检查这一行后:ActiveDocument.Tables(k).Range.Cells(j).Shading.BackgroundPatternColor
我看到它返回了-1。
我认为 -1 相当于 null 或 nil,这意味着单元格未填充,但如果是这样,为什么我可以看到 RGB 值?或者系统可能无法读取RGB值,但是这个系统到底是谁?
您是否有一个链接,其中很好地解释了 Shading.BackgroundPatternColor
方法?
I have a Word 2007 doc with a lot of tables. Each table has certain cells filled with 2 custom colors. I created a macro which takes for input 3 values to feed the RGB function, creating one of the colors, matches it against each of the colors, and changes the match with a new color.
I used an If
statement that compares the color of the filled cell with the color returned by the RGB function, feeding the function with the input given by the user.
If ActiveDocument.Tables(k).Range.Cells(j).Shading.BackgroundPatternColor = RGB(inputRed, inputGreen, inputBlue) Then
'code
end if
As I was looking through the document to see the results, I noticed that a few cells from 3 tables were left with the old color, so apparently the macro could not recognize it.
In Word 2007 I selected the cell that was supposed to have its color changed. I went to Home -> Shading -> More colors -> Custom and saw the 3 values that matched perfectly with the 3 values given as input by the user.
After 30 minutes of staring at the monitor, I thought about going to the doctor to have my eyes examined. :)
Before doing that though, I started to debug the app. on each of the cells that were not changed. Upon examining this line:ActiveDocument.Tables(k).Range.Cells(j).Shading.BackgroundPatternColor
I saw that it returned -1.
I am thinking -1 is the equivalent of null or nil, meaning that either the cell is not filled, but if so, why can I see the RGB values? Or perhaps the system can't read the RGB values, but who is this system exactly?
Do you have a link where the Shading.BackgroundPatternColor
method is well explained?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道 -1 的值,但 Word 2007 中的颜色略有变化,因此这些值不再一定是 RGB 值。我对此写了大量文章 - 请参阅 http://www.wordarticles.com/Articles/颜色/2007.php
I don't know about a value of -1, but colours in Word 2007 changed slightly so that the values were no longer necessarily RGB values. I have written extensively on this - please see http://www.wordarticles.com/Articles/Colours/2007.php