按键后循环期间执行代码

时间:2015-11-18 18:43:57

标签: excel vba excel-vba

我想在每次操作时执行一些代码,例如在循环期间的任何时候按空格键。只是不知道该怎么做。

Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub Startvogelpiek()
Dim rngCursor As Range
Dim rgbWit As Long
Dim rgbZwart As Long
Dim lngSnelheid As Long

Set rngCursor = Range("AL5:AX5")
rgbWit = RGB(255, 255, 255)
rgbZwart = RGB(0, 0, 0)
lngSnelheid = Range("AZ8").Value

For aantalkeer = 1 To 20
For teller = 1 To 13
    If rngCursor.Cells(teller - 1).Interior.Color = rgbZwart Then
        rngCursor.Cells(teller - 1).Interior.Color = rgbWit
    End If
    rngCursor.Cells(teller).Interior.Color = rgbZwart

'If **Spacebar_pressed** Then

rngCursor.Cells(teller).Interior.Color = RGB(125,125,125)

Exit Sub

End If

        Sleep lngSnelheid
        If rngCursor.Cells(13).Interior.Color = rgbZwart Then
            rngCursor.Cells(13).Interior.Color = rgbWit
        End If
    Next
    If aantalkeer = 20 Then
        MsgBox ("Uw tijd is afgelopen.")
        Exit For
    End If
    Next

    End Sub

0 个答案:

没有答案