I am writing a tutorial about using time in Excel on my blog and I made a clock in Excel which can be started and paused from the same button using the following code :
Dim RunClk As Boolean
-----------------------
Sub RunPauseClk()
RunClk = Not (RunClk)
Do While RunClk = True
DoEvents
Range("A1") = TimeValue(Now)
Range("A2") = Now()
Loop
End Sub
It works fine but I would like to add two sounds, a ticking sound and alarm sound and I have problems with triggering the first sound in sync with the "seconds" arm.
I used the following code:
Sub RunPauseClk()
RunClk = Not (RunClk)
Do While RunClk = True
DoEvents
Call PlaySound(ThisWorkbook.Path & "\button5.wav", 0&, &H2 Or &H20000)
Range("B3") = TimeValue(Now)
Range("B9") = Now()
Loop
End Sub
It produces the sound and I tried H1, H2, H4 etc and I don't seem to be able to synchronize the sound with the seconds.
You can download the file from : http://excelunusual.com/archive/2010/12/time-in-vba-japanese-clocks/ The clocks work but I removed the sound effects.
Thanks, George
Dim RunClk As Boolean
-----------------------
Sub RunPauseClk()
RunClk = Not (RunClk)
Do While RunClk = True
DoEvents
Range("A1") = TimeValue(Now)
Range("A2") = Now()
Loop
End Sub
It works fine but I would like to add two sounds, a ticking sound and alarm sound and I have problems with triggering the first sound in sync with the "seconds" arm.
I used the following code:
Sub RunPauseClk()
RunClk = Not (RunClk)
Do While RunClk = True
DoEvents
Call PlaySound(ThisWorkbook.Path & "\button5.wav", 0&, &H2 Or &H20000)
Range("B3") = TimeValue(Now)
Range("B9") = Now()
Loop
End Sub
It produces the sound and I tried H1, H2, H4 etc and I don't seem to be able to synchronize the sound with the seconds.
You can download the file from : http://excelunusual.com/archive/2010/12/time-in-vba-japanese-clocks/ The clocks work but I removed the sound effects.

Thanks, George
Last edited: