1
votes

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.

How can I then convert the following code into something that will work in Excel 2003?

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

Note: I use this for changing cell properties.

2

2 Answers

1
votes

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.

    With Selection.Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .Color = 5296274

    If Application.Version >= 12 then
    .TintAndShade = 0
    .PatternTintAndShade = 0
    End If

    End With
0
votes

.PatternTintAndShade was added in version 2007, so is simply not available in 2003

.TintAndShade is not applicable to ranges in 2003 (only shapes)

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.

EDIT

While the record can be useful, it will often produce more code than is required for your purpose, especially when setting format etc. And it 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

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)

Sub Macro1()
    With Selection.Interior
        .ColorIndex = 6
        .Pattern = xlSolid
    End With
End Sub