Option Explicit
Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
'
Private UserFormIsActive As Boolean
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
UserFormIsActive = False
End Sub
Private Sub UserForm_Activate()
UserFormIsActive = True
Do While UserFormIsActive
With Me.CommandButtonCapsLock
If GetCapsState Then .BackColor = vbGreen Else .BackColor = vbRed
End With
With Me.CommandButtonNumLock
If GetNumState Then .BackColor = vbGreen Else .BackColor = vbRed
End With
DoEvents
Sleep 10
Loop
End Sub