+ Reply to Thread
Results 1 to 5 of 5

Sleep function between commands

  1. #1
    Registered User
    Join Date
    07-18-2009
    Location
    Waterloo, Canada
    MS-Off Ver
    Excel 2020
    Posts
    20

    Sleep function between commands

    I am writing a macro that copies some data from an excel sheet and pastes it into a browser text box.

    I have everything figured out, and the code seems to working. Except that at some parts the commands are running so fast that they are not being executed in the proper order.

    For example in the code below:

    Please Login or Register  to view this content.
    As you can see the macro switches to the explorer window, and then a Sendkey {TAB} command is used to move the cursor to the first textbox. However at times the sendkey command is executed so fast that the TAB is being applied in the excel window. I'm not sure if I am explaining this correctly, but that's what I observe.

    I know there is a Sleep command to implement a wait time before the next command, but I don't know how to work that. Can someone please help me out here.

    Thanks.

  2. #2
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: Sleep function between commands

    rishadjb,

    Try (you may have to adjust the 5000 delay):

    Please Login or Register  to view this content.
    Have a great day,
    Stan

    Windows 10, Excel 2007, on a PC.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  3. #3
    Registered User
    Join Date
    07-18-2009
    Location
    Waterloo, Canada
    MS-Off Ver
    Excel 2020
    Posts
    20

    Re: Sleep function between commands

    Thanks Stanley.

    I'll play around with the time and figure out the most appropriate one.

    However, can you explain to me in what unit is this interval measured. As in this 5000, is it 5000 millisecs?

    EDIT: Nvm, just saw the declaration at the top, that its in millisecs.
    Last edited by rishadjb; 09-01-2009 at 09:04 PM.

  4. #4
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: Sleep function between commands

    rishadjb,

    Sorry, 5000 millisecs = 5 seconds

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Sleep function between commands

    Hello rishadjb,

    Sleep will suspend all CPU activity and input until the interval is expired.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

+ 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