1

1) How long is the minimum achievable delay time in vba excel? A pause using Application.Wait (Now + (ms * 1)) works just above a certain interval, and putting for example ms*0.001 gives the same pause as ms*0.1, or I'm wrong making delay?

2) How could I get a more precise delay execution? Running this simple test you'll give different value of real delay, which is worse as it is smaller pause.

I use the proposes offered here (How to give a time delay of less than one second in excel vba? ), but I repeat I need an exact time delay and to know how much that delay could be small.

Sub time_test()
    Dim t As Single
    t = Timer
    Application.Wait (Now + TimeValue("0:00:1"))
    MsgBox Timer - t
End Sub
Shivid
  • 1,295
  • 1
  • 22
  • 36
  • I saw that for sure , but my question is somehow different; using those proposed approaches there don't return me an exact delay if you test my code. Furthermore the exact same codes are insensible to the values less than 1 millisecond, so don't meet my necessities though. – Shivid Jan 01 '17 at 01:58
  • 1
    Please remember that, even if the `Wait` did wait for **exactly** one second, the `MsgBox` would not show that - because there is time involved, prior to waiting, in storing the current `Timer` value into the memory location allocated to `t` and then, after waiting, looking up the value at location `t`, looking up the `Timer`, and subtracting the two values. – YowE3K Jan 01 '17 at 02:08
  • Maybe http://stackoverflow.com/q/7103552/6535336 will assist you. – YowE3K Jan 01 '17 at 02:10
  • 1
    `Wait` isn't guaranteed to wait by that precise amount. It is impossible to use it if precision is important. Using a loop which checks `Timer` (with `DoEvents` in the body of the loop) will give you reasonable precision to around a 10th of a second (I sometimes use it for chart animations) but again -- it isn't high-precision. Maybe this will help: http://analystcave.com/vba-sleep-vs-wait/ – John Coleman Jan 01 '17 at 02:27
  • @YowE3K I'm sure that it is reasonably accurate. I based my comment on the documentation which has an example which said "This example pauses a running macro for approximately 10 seconds." (https://msdn.microsoft.com/en-us/library/office/ff822851.aspx). The "approximately" suggested that there wasn't any guarantees about exactly when the interpreter thread would get around to checking the system clock. I would expect some variability, maybe on a millisecond scale. – John Coleman Jan 01 '17 at 02:38

0 Answers0