2015-04-22 3 views
0

просто играл с vba, хотел посмотреть, смогу ли я сделать экран мигающим, но у вас проблемы.Изменить цвет фона на основе текущего цвета фона

Я получаю объектную ошибку на данный момент.

Sub disco() 

Dim col As Range 
Cells.Select 
Set col = Selection.Interior.ColorIndex 

If col = 0 Then 
     Selection.Interior.ColorIndex = 1 
ElseIf col = 1 Then 
     Selection.Interior.ColorIndex = 0 
End If 

Range("a1").Select 
End Sub 

ответ

0

Try:

Sub disco() 
    Dim col As Variant 
    Cells.Select 
    col = Selection.Interior.ColorIndex 
    If col = -4142 Then 
      Selection.Interior.ColorIndex = 1 
    ElseIf col = 1 Then 
      Selection.Interior.ColorIndex = -4142 
    End If 
    Range("a1").Select 
End Sub 

ПРИМЕЧАНИЯ:

мы используем Col как Вариант
мы не используем 0