Amish said:
I'm trying to create a macro that will meter a mail merge over several
days, but it looks like the Timer function is counting the number of
seconds since midnight. Does this mean that it will reset at midnight,
or will it continue processing until the macro completes its
iterations?
Yes, the value returned from Timer resets at midnight every day. There are other
system timers that only rollover every 42 days or so, but that too can be an issue
on machines that rarely get rebooted.
To determine how long a process takes, the simplest and most reliable method is to
note the start time and subtract that from the current time whenever you need to
know. IOW...
Dim StartTime As Date
Dim EndTime As Date
' Begin process
StartTime = Now
' Work, work, work...
EndTime = Now
If you need to display that, all purdy-like, for your users you can do something
like this:
Debug.Print FormatDHMS(DateDiff("s", StartTime, EndTime))
Public Function FormatDHMS(ByVal Seconds As Long, Optional Absolute As Boolean =
True) As String
Dim Rtn As String
Dim d As Long, h As Long, m As Long, s As Long
Const fmt As String = "00"
If Absolute Then Seconds = Abs(Seconds) 'avoid negative values
d = Seconds \ 86400 'days
h = (Seconds \ 3600) Mod 24 'hours
m = (Seconds \ 60) Mod 60 'minutes
s = Seconds Mod 60 'seconds
h = h Mod 24
If d Then Rtn = CStr(d) & " Days, "
If (h <> 0) Or (Len(Rtn) > 0) Then Rtn = Rtn & Format$(h, fmt) & " Hours, "
If (m <> 0) Or (Len(Rtn) > 0) Then Rtn = Rtn & Format$(m, fmt) & " Minutes,
and "
If (s <> 0) Or (Len(Rtn) > 0) Then Rtn = Rtn & Format$(s, fmt) & " Seconds"
FormatDHMS = Rtn
End Function
Later... Karl