+ Reply to Thread
Results 1 to 15 of 15

code to wait for 30 seconds?

  1. #1
    Forum Contributor
    Join Date
    12-11-2013
    Location
    St Moritz, GR, Switzerland
    MS-Off Ver
    Excel 2010
    Posts
    187

    code to wait for 30 seconds?

    Please Login or Register  to view this content.
    This is meant to run when the file is opened, wait 5 sec then give me the message box. What am I missing?

    Context: Now I have a clearer idea what I'm trying to achieve. Longer term I'm attempting to make a file automatically save and close a minute after it has been opened. I'm beginning simple so I stay on top of it.

  2. #2
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,418

    Re: code to wait for 30 seconds?

    Please Login or Register  to view this content.

  3. #3
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: code to wait for 30 seconds?

    I think to use sleep you need to define it as a function, I can't remember what the library to reference is.

    You can just use:
    Please Login or Register  to view this content.
    though, don't think you need the sleep function unless you want milliseconds.

    Edit: I remembered:
    Please Login or Register  to view this content.
    Last edited by ragulduy; 01-14-2014 at 09:42 AM.

  4. #4
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: code to wait for 30 seconds?

    Try this..

    Add this to your Workbook OPen event..

    Please Login or Register  to view this content.
    Put this in a Module..

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    12-11-2013
    Location
    St Moritz, GR, Switzerland
    MS-Off Ver
    Excel 2010
    Posts
    187

    Re: code to wait for 30 seconds?

    Yudlugar: I get 'runtime error 13, type mismatch' and end, debug or help.
    Bsalv: Thanks, but can I do it without the frozen egg timer? So the user can still use the file during the wait?

  6. #6
    Forum Contributor
    Join Date
    12-11-2013
    Location
    St Moritz, GR, Switzerland
    MS-Off Ver
    Excel 2010
    Posts
    187

    Re: code to wait for 30 seconds?

    Apo: I'll try but I'll have to figure the interface.
    Edit: That works, Apo however my object is to let the user have a short time to edit the file which then shuts ready or not. 'Sleep' freezes Excel entirely until it's up :-(
    Last edited by johnandrews; 01-14-2014 at 09:52 AM.

  7. #7
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: code to wait for 30 seconds?

    @johnandrews - Apo has given you the solution I believe, I forgot you can't put the sleep lib bit in an object module.

  8. #8
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: code to wait for 30 seconds?

    Hi..

    You're right.. try this 'workaround'...
    Please Login or Register  to view this content.

  9. #9
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,418

    Re: code to wait for 30 seconds?

    you can use "ontime" to create a job in the future.
    For example you want to close your workmap without saving. This can be done by the macro "shutdown"
    But suppose that you want it after 30 seconds and meanwhile use the workmap, then you run the macro "ShutDownAfter30Sec"

    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    12-11-2013
    Location
    St Moritz, GR, Switzerland
    MS-Off Ver
    Excel 2010
    Posts
    187

    Re: code to wait for 30 seconds?

    Apo, that works ;-)
    Bsalv: My Excel doesn't like

    Please Login or Register  to view this content.
    Is there another code for save & close?

  11. #11
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,418

    Re: code to wait for 30 seconds?

    make the parameter savechanges 1 and it 'll save and close
    Please Login or Register  to view this content.

  12. #12
    Forum Contributor
    Join Date
    12-11-2013
    Location
    St Moritz, GR, Switzerland
    MS-Off Ver
    Excel 2010
    Posts
    187

    Re: code to wait for 30 seconds?

    Please Login or Register  to view this content.
    ...works to save and shut, but I forgot I had this set to run when the file opens. Try and open it, it shuts again. Only I would do that...

  13. #13
    Forum Contributor
    Join Date
    12-11-2013
    Location
    St Moritz, GR, Switzerland
    MS-Off Ver
    Excel 2010
    Posts
    187

    Re: code to wait for 30 seconds?

    Please Login or Register  to view this content.
    Now I'm even more confused. Why, with this code, does it open and shut without waiting? To edit it, I disabled Macros in the Trust Centre.

  14. #14
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,418

    Re: code to wait for 30 seconds?

    the open-macro in ThisWorkbook 'll call the macro "ShutDownAfter30Sec".
    Now you can work in the workbook, but after 30 sec the workbook 'll close and save the changes.
    Attached Files Attached Files

  15. #15
    Forum Contributor
    Join Date
    12-11-2013
    Location
    St Moritz, GR, Switzerland
    MS-Off Ver
    Excel 2010
    Posts
    187

    Re: code to wait for 30 seconds?

    That works.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 2
    Last Post: 09-21-2013, 10:49 AM
  2. [SOLVED] Wait 2 seconds, then GOTO X
    By The Phil in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-26-2013, 04:33 PM
  3. This forum requires that you wait 30 seconds between searches
    By Pepe Le Mokko in forum Suggestions for Improvement
    Replies: 2
    Last Post: 04-07-2013, 11:49 PM
  4. [SOLVED] Macro to wait 5 seconds before running next line
    By Jiptastic in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-27-2013, 11:22 AM
  5. How To Wait 2 Seconds After Msgbox & Then Continue
    By Launchnet in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-26-2010, 12:16 PM

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