+ Reply to Thread
Results 1 to 10 of 10

Stop and restart macro(s) programatically

  1. #1
    Forum Contributor JP Romano's Avatar
    Join Date
    10-09-2008
    Location
    Princeton, NJ
    MS-Off Ver
    2010
    Posts
    500

    Stop and restart macro(s) programatically

    Good day all,
    I've got a series of macros in place which, essentially, download several CSV files into a temp directory, then opens each and copies the data into a single workbook (one sheet).

    What happens is that the some number of the sheets don't actually open until the macro stops. I've tried using the wait (Application.Wait Now + TimeValue("00:00:10")) and sleep functions, but it's not quite doing what I want.

    What I'd LIKE to do is have the macro actually STOP processing for 10 seconds, then proceed (or start a new macro).

    I've also tried putting the wait behind a button in a userform, which is non modal... the csv files open until the user clicks the button.

    Help?

    Thanks!
    Last edited by JP Romano; 01-20-2010 at 03:50 PM.

  2. #2
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: Stop and restart macro(s) programatically

    This may be more the case that Windows/Excel is not updating the windowing environment while your macro is running. I have noticed on long running macros that I will sometimes get an new instance of Excel in the Task Bar which subsequently disappears when the macro completes.

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Stop and restart macro(s) programatically

    What causes the delay? Time in copying the files?
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Forum Contributor JP Romano's Avatar
    Join Date
    10-09-2008
    Location
    Princeton, NJ
    MS-Off Ver
    2010
    Posts
    500

    Re: Stop and restart macro(s) programatically

    Blane...thanks...will look into that as well.

    Shg -
    Basically, I click a link on another application, which then downloads a file to my temp directory. Then the next link, then the next, etc (up to 40 of these files daily). All that works fine. The problem is that when each file is downloaded, it automatically opens - unless a marco is running (including one running a "wait" or "sleep"). When the macro stops or is completed, the files all open.

    I just want to stop all macro activity to give these downloaded files a chance to open, then proceed with the macro, or another one. 10-20 seconds should be more than enough...

    I hope that makes sense...

  5. #5
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: Stop and restart macro(s) programatically

    Quote Originally Posted by JP Romano View Post
    The problem is that when each file is downloaded, it automatically opens
    Maybe you could serialize this. Wait until all of the files are downloaded, then open process each one in turn. Is there some reason why they are being opened automatically when the download is complete?

  6. #6
    Forum Contributor JP Romano's Avatar
    Join Date
    10-09-2008
    Location
    Princeton, NJ
    MS-Off Ver
    2010
    Posts
    500

    Re: Stop and restart macro(s) programatically

    Blane - Yeah, I'm trying to wait until they all open, but the problem is still kind of the same - how do I continuously check for the existence of an open file if the file won't open while the macro is running?

    Unfortunately, the fact that they open when downloaded is a limitation I have to live with...it's a function of the application I'm working with and it's been made quite clear to me that it will not be changed for any reason!

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Stop and restart macro(s) programatically

    You could use the OnTime method, and schedule a macro run at 1s intervals. It would check to see what files are open, and reschedule itself to run again until they're all open. When they are, it would run the next macro.

    Help has a good example.

  8. #8
    Forum Contributor JP Romano's Avatar
    Join Date
    10-09-2008
    Location
    Princeton, NJ
    MS-Off Ver
    2010
    Posts
    500

    Re: Stop and restart macro(s) programatically

    Thanks... I had tried that unsuccessfully, but will give it another go. Thanks again for your time!

  9. #9
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Stop and restart macro(s) programatically

    Holler back if you have problems.

  10. #10
    Forum Contributor JP Romano's Avatar
    Join Date
    10-09-2008
    Location
    Princeton, NJ
    MS-Off Ver
    2010
    Posts
    500

    Re: Stop and restart macro(s) programatically

    Thanks...I most certainly won't hesitate.
    Ran the first test this afternoon, and the end user was quite pleased.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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