vba Excel 2003 中的 TintAndShade 和 PatternTintAndShade
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7773526/
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
TintAndShade and PatternTintAndShade in Excel 2003
提问by Reinstate Monica - Goodbye SE
I added TintAndShade
and PatternTintAndShade
to an Excel 2007 vba macro. A colleague tried them out in Excel 2003 and found that those commands did not work there.
我将TintAndShade
和添加PatternTintAndShade
到 Excel 2007 vba 宏。一位同事在 Excel 2003 中试用了它们,发现这些命令在那里不起作用。
How can I then convert the following code into something that will work in Excel 2003?
我如何才能将以下代码转换为可以在 Excel 2003 中使用的代码?
With Selection.Interior .Pattern = xlSolid .PatternColorIndex = xlAutomatic .Color = 5296274 .TintAndShade = 0 .PatternTintAndShade = 0 End With
With Selection.Interior .Pattern = xlSolid .PatternColorIndex = xlAutomatic .Color = 5296274 .TintAndShade = 0 .PatternTintAndShade = 0 End With
where the lines that need conversion are:
需要转换的行是:
.TintAndShade = 0 .PatternTintAndShade = 0
.TintAndShade = 0 .PatternTintAndShade = 0
Note: I use this for changing cell properties.
注意:我使用它来更改单元格属性。
采纳答案by TheFuzzyGiggler
TintandShade only works for shapes in Excel 2003. Cells are stuck with the standard ugly colors. You can make your code conditional based on version though.
TintandShade 仅适用于 Excel 2003 中的形状。单元格使用标准的难看颜色。不过,您可以根据版本使代码有条件。
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 5296274
If Application.Version >= 12 then
.TintAndShade = 0
.PatternTintAndShade = 0
End If
End With
回答by chris neilsen
.PatternTintAndShade
was added in version 2007, so is simply not available in 2003
.PatternTintAndShade
已在 2007 版中添加,因此在 2003 年根本不可用
.TintAndShade
is not applicable to ranges in 2003 (only shapes)
.TintAndShade
不适用于 2003 年的范围(仅形状)
That said, setting these to 0 nullifies their effect, so unless there is something you are not telling us you may not need to use them at all.
也就是说,将这些设置为 0 会使它们的效果无效,因此除非您没有告诉我们某些事情,否则您可能根本不需要使用它们。
EDIT
编辑
While the record can be useful, it will often produce more code than is required for your purpose, especially when setting format etc. Andit can produce different code in different versions. So use it as a guide, not a gospel.
虽然记录很有用,但它通常会生成比您的目的所需的更多的代码,尤其是在设置格式等时。 并且它可以在不同的版本中生成不同的代码。所以用它作为指南,而不是福音。
Eg Setting a fill colour on a range (using toolbar paint)
例如在范围上设置填充颜色(使用工具栏绘制)
Excel 2010
Excel 2010
Sub Macro1()
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End Sub
Excel 2003 (and running this macro in 2010 produces the same result as in 2003)
Excel 2003(并在 2010 年运行此宏产生与 2003 年相同的结果)
Sub Macro1()
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
End Sub