Timer

E

ED

Can you get the Timer control to work in VBA in Office XP? I have tried turning on References and Additional Controls but it won't come up in the ToolBox.
 
P

Peter Hewett

Hi =?Utf-8?B?RUQ=?=

As you've discovered there's no Timer control in VBA and youi can't use the
VB one. Here's the common workaround:

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private Sub Doze(ByVal lngPeriod As Long)
DoEvents
Sleep lngPeriod
End Sub

HTH + Cheers - Peter
 
L

Lars-Eric Gisslén

Ed,

If you want to use a plain timer in your code you can use the following code
as an example. (Only for Word 2000 and later)
------------------------------------------------------
' Win API declarations
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 hTimer As Long
Dim nCount As Long

Sub StartTimer()
Dim nMilliSec As Long

nMilliSec = 1000 ' set timer events to 1 second
hTimer = SetTimer(0, 0, nMilliSec, AddressOf TimerProc)

End Sub

Sub StopTimer()
KillTimer 0, hTimer
End Sub

Sub TimerProc()
nCount = nCount + 1

If nCount > 10 Then StopTimer

Selection.TypeText Now()
Selection.TypeParagraph

End Sub
----------------------------------------------

--
Regards,
Lars-Eric Gisslén

ED said:
Can you get the Timer control to work in VBA in Office XP? I have tried
turning on References and Additional Controls but it won't come up in the
ToolBox.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top