Option Explicit

Declare Function SetTimer Lib "user32" ( _
ByVal hwnd As Long, _
ByVal nIDEvent As Long, _
ByVal uElapse As Long, _
ByVal lpTimerfunc As Long) As Long

Declare Function KillTimer Lib "user32" ( _
ByVal hwnd As Long, _
ByVal nIDEvent As Long) As Long

'==========Public Declarations ==============================
Public TimerID As Long 'Turn on and off with this ID
Public TimerActive As Boolean 'Is the timer active
Public Const tmMin As Long = 2 'Minimum time allowed
Public Const tmDef As Long = 5 'Default if min set to tmMin
'============================================================

Public Sub ActivateMyTimer(ByVal sec As Long)
sec = sec * 1000
If TimerActive Then Call DeActivateMyTimer

On Error Resume Next
TimerID = SetTimer(0, 0, sec, AddressOf Timer_CallBackFunction)
TimerActive = True

End Sub

Public Sub DeActivateMyTimer()
KillTimer 0, TimerID
End Sub

Function Timer_CallBackFunction( _
ByVal hwnd As Long, _
ByVal uMsg As Long, _
ByVal idevent As Long, _
ByVal Systime As Long) As Long

SendKeys "%C", True
If TimerActive Then Call DeActivateMyTimer

End Function


Sub PrintPreview()
'// Set timer for 5 secs change as required
'// But min is set @ 5
ActivateMyTimer 5
ActiveWindow.SelectedSheets.PrintPreview
MsgBox "The rest of my code is running"
End Sub