我正在使用使某些单元格闪烁的代码。我修改了代码,只让选定的单元格闪烁。问题是,在更改选择后,宏不会与单元“保持”。 例如:如果我选择单元格B6并运行宏 - 它开始闪烁,然后我选择单元格B7和B6停止闪烁但B7启动,甚至没有运行宏。 我怎么能解决这个问题?
当前代码:
Option Explicit
Dim NextBlink As Double
Sub StartBlinking()
If Selection.Interior.ColorIndex = 3 Then
Selection.Interior.ColorIndex = 0
Else
Selection.Interior.ColorIndex = 3
End If
NextBlink = Now + TimeSerial(0, 0, 0.6)
Application.OnTime NextBlink, "StartBlinking", , True
End Sub
答案 0 :(得分:1)
试试这个:
Option Explicit
Dim NextBlink As Double
Dim blinkingcells As Range
Sub StartBlink() 'call this make current cell start blinking
If blinkingcells Is Nothing Then
'start blinking
Set blinkingcells = Selection
Call Blinking
Else
'blinking already, just add more blinkingcells
Set blinkingcells = Union(blinkingcells, Selection)
End If
End Sub
Sub Blinking()
'make cells in global range "blinkingcell" blink
Dim cell As Range
For Each cell In blinkingcells
If cell.Interior.ColorIndex = 3 Then
cell.Interior.ColorIndex = 0
Else
cell.Interior.ColorIndex = 3
End If
Next
NextBlink = Now + TimeSerial(0, 0, 0.6)
Application.OnTime NextBlink, "Blinking", , True
End Sub