+ Reply to Thread
Results 1 to 8 of 8

How to stop Macro from looping

  1. #1
    Registered User
    Join Date
    11-11-2007
    Posts
    44

    How to stop Macro from looping

    Hello all,

    I have a macro code that automatically saves after every 15 minutes. however, after closing the sheet (not excel) and opening a new program. It opens the program with the macro that saves every 15 minutes without me trying to open it.

    Here's the code in ThisWorkbook
    Please Login or Register  to view this content.
    Code in Modules

    Module 1
    Please Login or Register  to view this content.
    Module 2
    Please Login or Register  to view this content.
    Thanks for your help.

  2. #2
    Registered User
    Join Date
    11-25-2007
    Posts
    46
    Does appear you have an infinite loop.

    Sub saveIT calls Sub UpdateTime. Sub UpdateTime calls sub saveIT. There is no stopping mechanism. Both are in modules of this workbook.

    To clarify, you have closed the Excel workbook containing these modules, but not Excel (correct?). The some other program you launched is saving every 15 minutes? Can you tell us what that other program might be? Maybe we could try to recreate the situation with more details.

    Cam

  3. #3
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,482
    Please elaborate between closing a sheet, and closing a workbook...

  4. #4
    Registered User
    Join Date
    11-11-2007
    Posts
    44
    Quote Originally Posted by ctmurray
    Does appear you have an infinite loop.

    Sub saveIT calls Sub UpdateTime. Sub UpdateTime calls sub saveIT. There is no stopping mechanism. Both are in modules of this workbook.

    To clarify, you have closed the Excel workbook containing these modules, but not Excel (correct?). The some other program you launched is saving every 15 minutes? Can you tell us what that other program might be? Maybe we could try to recreate the situation with more details.

    Cam
    To clarify, let's say I close the workbook (but not excel) and I open a another spreadsheet or a new sheet. For some reason, a window that ask to enable macro opens and if I click enable or disable, the spreadsheet that contains the macro to autosave every 15 minutes pops-up, and if i close it, it will re-open after 15 minutes. It seems like the code resides in the memory and it doesn't clear until I close the excel program.

    Is there another way to autosave the sheet ever 15 minutes (specified time) besides using the code i'm using?

    Thanks in advance.

  5. #5
    Registered User
    Join Date
    11-11-2007
    Posts
    44
    Quote Originally Posted by davesexcel
    Please elaborate between closing a sheet, and closing a workbook...
    Dave, sorry for the confusion.
    I meant closing the workbook, not excel.

    thanks.

  6. #6
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    As far as I know when you use Application.Ontime to set a macro to run in the future, as long as you do not close Excel the macro will run.

    If the workbook the macro is in closed at the time the macro is due to run, the Application.Ontime event opens the workbook so the macro can run
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

  7. #7
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    Putting this in the ThisWorkbook code module should disable the OnTime.
    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  8. #8
    Registered User
    Join Date
    11-11-2007
    Posts
    44
    Quote Originally Posted by mikerickson
    Putting this in the ThisWorkbook code module should disable the OnTime.
    Please Login or Register  to view this content.
    For some reason this is not working. Is it because of Workbook_BeforeClose?

    thank you.

+ 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