Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 5 of 5

Thread: Ending a Macro at a specified time

  1. #1
    New Member
    Join Date
    Apr 2002
    Posts
    17
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    How do I get a macro to end after 1 minute of running. The macro was written to run a refresh on a Web Query (excel 2000), but if the macro is searcing for the data for over 1 minute, I would rather it stopped looking, and started all over again.

    Thanks
    Hios@interaccess.com

  2. #2
    MrExcel MVP Al Chara's Avatar
    Join Date
    Feb 2002
    Location
    Newark, Delaware
    Posts
    1,701
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Try using the NOW and ONTIME functions.
    Best regards,
    Allan Chara
    http://www.mrspreadsheets.com

  3. #3
    New Member
    Join Date
    Apr 2002
    Posts
    17
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    I Understand how to use the NOW and ONTIME functions to start a macro, but how do I use them to stop a macro from running. I think a simple example is all I need to figure it out.

    Thanks for the quick response.

  4. #4
    MrExcel MVP Al Chara's Avatar
    Join Date
    Feb 2002
    Location
    Newark, Delaware
    Posts
    1,701
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Try the following:

    Dim StartTime, Duration As Integer
    StartTime = Second(Now)
    Duration = 3
    Do
    counter = counter + 1
    Loop Until Second(Now) > StartTime + Duration
    MsgBox "This macro looped " & counter & " times in " & Duration & " seconds"
    Best regards,
    Allan Chara
    http://www.mrspreadsheets.com

  5. #5
    New Member
    Join Date
    Apr 2002
    Posts
    17
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Works Great!

    Thanks again for your help.


Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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