Hacer parpadear una celda

En este ejemplo se muestra cómo hacer que la celda B2 de la hoja 1 parpadee cambiando el color y el texto del rojo al negro, y viceversa, en el procedimiento StartBlinking. El procedimiento StopBlinking muestra cómo detener el parpadeo desactivando el valor de la celda y estableciendo la propiedad ColorIndex en blanco.

Código de ejemplo provisto por: Tom Urtis, Atlas Programming Management

Option Explicit

Public NextBlink As Double
'The cell that you want to blink
Public Const BlinkCell As String = "Sheet1!B2"

'Start blinking
Private Sub StartBlinking()
    Application.Goto Range("A1"), 1
    'If the color is red, change the color and text to white
    If Range(BlinkCell).Interior.ColorIndex = 3 Then
        Range(BlinkCell).Interior.ColorIndex = 0
        Range(BlinkCell).Value = "White"
    'If the color is white, change the color and text to red
    Else
        Range(BlinkCell).Interior.ColorIndex = 3
        Range(BlinkCell).Value = "Red"
    End If
    'Wait one second before changing the color again
    NextBlink = Now + TimeSerial(0, 0, 1)
    Application.OnTime NextBlink, "StartBlinking", , True
End Sub

'Stop blkinking
Private Sub StopBlinking()
    'Set color to white
    Range(BlinkCell).Interior.ColorIndex = 0
    'Clear the value in the cell
    Range(BlinkCell).ClearContents
    On Error Resume Next
    Application.OnTime NextBlink, "StartBlinking", , False
    Err.Clear
End Sub

Acerca del colaborador

Tom Urtis, MVP, es el fundador de Atlas Programming Management, una empresa de Silicon Valley que ofrece soluciones empresariales integrales de Microsoft Office y Excel. Tom tiene más de 25 años de experiencia en la administración de negocios y el desarrollo de aplicaciones de Microsoft Office. Es, además, coautor de "Holy Macro! 2500 ejemplos de VBA para Excel".

Soporte técnico y comentarios

¿Tiene preguntas o comentarios sobre VBA para Office o esta documentación? Vea Soporte técnico y comentarios sobre VBA para Office para obtener ayuda sobre las formas en las que puede recibir soporte técnico y enviar comentarios.