use Excel Now() in VBA
sorry about the double post
"Helmut Meukel" wrote in message
...
"Peter T" <peter_t@discussions schrieb im Newsbeitrag
...
FWIW Now() normally gets coerced to one second in cells due to the Date
type conversion. However it's actual resolution is to 1/100 sec (at least
in my light testing) so maybe simply -
dim x as double
x = [now()]
Wrong, dead wrong.
Try the same in VB6:
Time() and Now() don't return any fractions of a second.
Time() and Now() use identical code in VB6 and VBA because
it's in the very same DLL: MSVBVM60.DLL
The date data type is internally a double, where the integer part
is the day - starting with 12/30/1899 as day 0 -
and the fractional part is the time - starting at midnight with .0000
Thus .25 is 6:00 AM, .75 is 6:00 PM
Being internally a double, a date data type could hold fractions of
seconds.
The Excel spreadsheet function Now() has the same name as the
VBA function but is more accurate.
If you use the brackets VBA will use the excel function instead of
its own function.
Excel has it's own date/time functions because they were first there.
VBA was added to Excel with Excel 95.
Helmut.
What is it you think I said that is wrong. I didn't mention anything about
VBA's Now function, only that Excel's Now() has a resolution of 1/100sec in
my light testing (see below)
Sub test()
Dim b As Boolean, x#, y#
Const sec# = 1 / (24& * 60 * 60)
x = [Now()]
b = True
While b
y = [now()]
b = x = y
Wend
Debug.Print sec / (y - x) ' about 100
End Sub
If you change [Now()] to Now I expect the debug will be about 1, ie VBA's
Now has a resolution of 1 second (not sure why you say you can return a
higher resolution VBA's Now)
FWIW I am well aware that the square brackets example I posted Evaluates
Excel's NOW() function.
Regards,
Peter T
|