+ Reply to Thread
Results 1 to 6 of 6

sleep vs wait

  1. #1
    Registered User
    Join Date
    03-16-2009
    Location
    italy
    MS-Off Ver
    Excel 2003
    Posts
    64

    sleep vs wait

    hello i'm asking whether there are differences between the following lines, many thanks

    Application.Wait Now + TimeValue("00:00:2")
    sleep 2000

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: sleep vs wait

    Ciao!

    I cannot find "sleep" as a valid statement or function. Where did you get it?
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: sleep vs wait

    Sleep is an API function (and therefore won't work without the relevant declaration).
    Remember what the dormouse said
    Feed your head

  4. #4
    Registered User
    Join Date
    03-16-2009
    Location
    italy
    MS-Off Ver
    Excel 2003
    Posts
    64

    Re: sleep vs wait

    you were right i happen to forget the declaration of api
    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

    and i was asking if there are any differences between
    sleep 2000
    ofcourse with declaration
    and the line

    Application.Wait Now + TimeValue("00:00:2")

    thankyou a lot

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: sleep vs wait

    I think the answer to your question is that they are inherently the same. Preference will rule here.

    However, if the purpose is to stop a macro so that you can do other tasks, it's not just a "pause for 2 seconds"... then you would use Application.OnTime. That would allow you to basically stop completely and get control back for a specified amount of time...then the macro (or another one) kicks off again at the appointed time.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  6. #6
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: sleep vs wait

    Sleep is more flexible since it uses milliseconds (though I wouldn't actually expect it to be that accurate) but they do basically the same thing.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1