none
Application.wait doesn't work RRS feed

  • Question

  • I work with office 2007, and the function application.wait doesn't work, it's not an option to use the sleepfunction instead, so is there an other way to let the application wait 0.5 sec or is there a declaration for the wait function? (it could also be that it is in a lib that isn't enabled, so in that case, in what lib is it situated?)
    Sunday, March 24, 2013 2:38 PM

Answers

  • I just found it: it doesn't exsist in word, but it does in excel, so i will run my program there :)
    • Marked as answer by Mr. Rik Monday, March 25, 2013 4:20 PM
    Sunday, March 24, 2013 8:13 PM

All replies

  • app.Wait only has a resolution of one second, eg,

    Application.Wait Now + TimeSerial(0, 0, 5)  'wait 5 seconds

    You could use the Timer function in a loop, something like this

    [vbnet]
    Dim timeOut As Single

    timeOut = Timer + 0.5  ' loop approx 0.5 seconds
    Debug.Print Timer
    Do While Timer < timeOut
    Loop
    Debug.Print Timer
    [vbnet]

    Note the Timer function has a relatively low resolution, for anything more accurate you would need to use one of a number of APIs

    Peter Thornton

    Sunday, March 24, 2013 6:04 PM
    Moderator
  • I rather don't use loops, they take a lot of memory, and the problem isn't the half second but just that this function doesn't exsist in VBA in word
    Sunday, March 24, 2013 8:11 PM
  • I just found it: it doesn't exsist in word, but it does in excel, so i will run my program there :)
    • Marked as answer by Mr. Rik Monday, March 25, 2013 4:20 PM
    Sunday, March 24, 2013 8:13 PM
  • The loop uses only trivial memory. You can't do anything else in VBA or it's host as the process is not asynchronous, but presumably that's the intention. If that's not the intention explain what you are doing. Also is there some reason you can't use Sleep.

    Peter Thornton

    Sunday, March 24, 2013 8:29 PM
    Moderator
  • that is indeed the intention, but i don't like to use loops because they use a lot of memory and with that also a lot of power, and the sleep function doesn't work synchronously in this particular program.

    but i'm working in excel now and it works fine over there. so problem solved, thanks for the help Peter Thornton :)

    Monday, March 25, 2013 4:20 PM