Option Explicit
#If VBA7 And Win64 Then
'64bit版
Private Declare PtrSafe Function SetTimer Lib "user32" _
(ByVal hwnd As LongPtr, ByVal nIDEvent As LongPtr, ByVal uElapse As LongPtr, ByVal lpTimerFunc As LongPtr) As LongPtr
#Else
'32bit版
Private Declare Function SetTimer Lib "user32" _
(ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
#End If
#If VBA7 And Win64 Then
'64bit版
Private Declare PtrSafe Function KillTimer Lib "user32" (ByVal hwnd As LongPtr, ByVal nIDEvent As LongPtr) As Long
#Else
'32bit版
Private Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
#End If
'Windowsが呼び出す関数。引数や戻り値は決まっている。TimerProcで検索すると見つかる
Public Sub TimerProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal TimerID As Long, ByVal TickCount As Long)
Debug.Print hwnd, Msg, TimerID, TickCount
KillTimer 0, TimerID 'タイマーを止める。Windowsに教える。
'ここにやりたことを書く
End Sub
Sub main()
SetTimer 0, 0, 1000 * 2, AddressOf TimerProc '1000で1秒。2秒後にTimeProcを呼び出す
End Sub