Um dos problemas do VBA é sua pobreza de bibliotecas. Tá bom, tem bastante coisa sim, mas comparado ao que vemos em linguagens mais novas como .NET e Java, pelo menos para que já desenvolve nestas linguagens sente muita falta de coisas já consideradas simples como enums para representar valores.

Opiniões a parte, os camaradas da OzGrid.com publicaram um função em VBA que retorna o nome da cor com base em um Range passado por parâmetro. Pelo menos ele suporta a principal paleta de cores do Microsoft Office, neste caso do Excel. A função segue abaixo:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
Function CellColor(rCell As Range, Optional ColorName As Boolean)
    Dim strColor As String, iIndexNum As Integer
 
    'Written by Dave Hawley of OzGrid.com
    Select Case rCell.Interior.ColorIndex
    Case 1
        strColor = "Black"
        iIndexNum = 1
    Case 53
        strColor = "Brown"
        iIndexNum = 53
    Case 52
        strColor = "Olive Green"
        iIndexNum = 52
    Case 51
        strColor = "Dark Green"
        iIndexNum = 51
    Case 49
        strColor = "Dark Teal"
        iIndexNum = 49
    Case 11
        strColor = "Dark Blue"
        iIndexNum = 11
    Case 55
        strColor = "Indigo"
        iIndexNum = 55
    Case 56
        strColor = "Gray-80%"
        iIndexNum = 56
    Case 9
        strColor = "Dark Red"
        iIndexNum = 9
    Case 46
        strColor = "Orange"
        iIndexNum = 46
    Case 12
        strColor = "Dark Yellow"
        iIndexNum = 12
    Case 10
        strColor = "Green"
        iIndexNum = 10
    Case 14
        strColor = "Teal"
        iIndexNum = 14
    Case 5
        strColor = "Blue"
        iIndexNum = 5
    Case 47
        strColor = "Blue-Gray"
        iIndexNum = 47
    Case 16
        strColor = "Gray-50%"
        iIndexNum = 16
    Case 3
        strColor = "Red"
        iIndexNum = 3
    Case 45
        strColor = "Light Orange"
        iIndexNum = 45
    Case 43
        strColor = "Lime"
        iIndexNum = 43
    Case 50
        strColor = "Sea Green"
        iIndexNum = 50
    Case 42
        strColor = "Aqua"
        iIndexNum = 42
    Case 41
        strColor = "Light Blue"
        iIndexNum = 41
    Case 13
        strColor = "Violet"
        iIndexNum = 13
    Case 48
        strColor = "Gray-40%"
        iIndexNum = 48
    Case 7
        strColor = "Pink"
        iIndexNum = 7
    Case 44
        strColor = "Gold"
        iIndexNum = 44
    Case 6
        strColor = "Yellow"
        iIndexNum = 6
    Case 4
        strColor = "Bright Green"
        iIndexNum = 4
    Case 8
        strColor = "Turqoise"
        iIndexNum = 8
    Case 33
        strColor = "Sky Blue"
        iIndexNum = 33
    Case 54
        strColor = "Plum"
        iIndexNum = 54
    Case 15
        strColor = "Gray-25%"
        iIndexNum = 15
    Case 38
        strColor = "Rose"
        iIndexNum = 38
    Case 40
        strColor = "Tan"
        iIndexNum = 40
    Case 36
        strColor = "Light Yellow"
        iIndexNum = 36
    Case 35
        strColor = "Light Green"
        iIndexNum = 35
    Case 34
        strColor = "Light Turqoise"
        iIndexNum = 34
    Case 37
        strColor = "Pale Blue"
        iIndexNum = 37
    Case 39
        strColor = "Lavendar"
        iIndexNum = 39
    Case 2
        strColor = "White"
        iIndexNum = 2
    Case Else
        strColor = "Custom color or no fill"
    End Select
 
    If ColorName = True Or _
       strColor = "Custom color or no fill" Then
        CellColor = strColor
    Else
        CellColor = iIndexNum
    End If
 
End Function

O uso da função é simples, bastando colocar em alguma célula a seguinte fórmula:

=CellColor(A1,TRUE)

Isso retorna o nome da cor segundo a paleta de cores. Omitir ou mecionar FALSE no segundo parâmetro, por exemplo:

=CellColor(A1,FALSE) OR CellColor(A1)

Trará o código da cor.

Abraços e bom proveito!

Tomás Vásquez
http://www.tomasvasquez.com.br

Fonte: ozgrid.com