Saturday, April 7, 2018

VBA Blinking on sheet (Excel VBA)

At first, open Excel and VBA window. Add a module from the window.

Right click on this or click Insert from the menu and insert a module.


In the module, add this code:
Sub Blink()
  Const ColorIdx1 = 37
  Const ColorIdx2 = xlColorIndexNone
If Worksheets("Sheet1").Range("A1").Interior.ColorIndex = ColorIdx1 Then
    Worksheets("Sheet1").Range("A1").Interior.ColorIndex = ColorIdx2
    Worksheets("Sheet1").Range("A2").Interior.ColorIndex = ColorIdx1
Else
    Worksheets("Sheet1").Range("A1").Interior.ColorIndex = ColorIdx1
    Worksheets("Sheet1").Range("A2").Interior.ColorIndex = ColorIdx2
End If
    Application.OnTime Now + TimeValue("00:00:01"), "Blink"
End Sub


Then add this code in ThisWorkBook:
Private Sub Workbook_Open()
 Blink
End Sub

ThisWorkbook is here.


Run the Blink function. A1 and A2 of Sheet1 will blink every 1 second.