View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Erick Erick is offline
external usenet poster
 
Posts: 2
Default Grab Time with milliseconds included in VBA

What I am looking for is to get the exact Date and Time down to the
Millisecond when I press a Shortcut Key. Peter, I am not exactly sure
what your code is telling me. It looks like it is timing how long it
takes your code to execute? Every time I run it I get a number in the
msgbox like "1,206,000". Is this supposed to be converting it into
milliseconds with the msgbox? Hmmm?

I decided to use =TEXT(NOW(),"hhmmss.00" formula and refreshing it,
grabbing the value and then putting it where I want it. It seems to
work ok like that. It might not be very accurate? Still more
accurate than me with a stopwatch.

Thank you for the code,
Eklassen



"Peter T" <peter_t@discussions wrote in message ...
Hi Erick,

If you are trying to return the time like a stopwatch you could use the
following API which returns the time in milliseconds since system startup:

Public Declare Function GetTickCount Lib "kernel32.dll" () As Long
Sub testTimer()
Dim t As Long
t = GetTickCount

For i = 1 To 1000000
a = a + 1
Next

MsgBox GetTickCount - t, , "Milliseconds"
End Sub

Regards,
Peter