Closing a save loop with Workbook_BeforeClose(Cancel As Boolean)

NMatheson

New Member
Joined
Jul 28, 2016
Messages
1
Hello everyone, new guy here.

I'm pulling my hair out as I cannot figure this out, no matter how many threads I read on it or tutorials I watch. Here's how this one works. On open, the app checks a location on the drive for a file of the same name. If its there, the workbook closes. If it's not, it is created and then autosaved every 2 minutes in an endless loop. Im trying to terminate this loop on close of the workbook. The "ThisWorkbook" module calls the "Sheet1" module, which contains the following -



Private CancelSave
Public Sub SaveWb()

CancelSave = DateAdd("n", 2, Time)

ThisWorkbook.Save
Application.OnTime CancelSave, "Sheet1.SaveWb"

End Sub
Public Sub Workbook_BeforeClose(Cancel As Boolean)

Application.OnTime CancelSave, "Sheet1.SaveWb", , False

End Sub



When I have any other workbooks open while I close this, the timer still continues and will open the old workbook up and start all over. I've spent days trying to trouble shoot this and I feel like there is something fundamental that I am misunderstanding. Thanks for the help in advance!
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Forum statistics

Threads
1,215,390
Messages
6,124,667
Members
449,178
Latest member
Emilou

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top