![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Feb 2002
Location: Stockton, California
Posts: 281
|
Hi everyone, I'm having a problem. I have a few macros in modules as follows:
Dim DownTime As Date Sub SetTime() DownTime = Now + TimeValue("00:5:00") Application.OnTime DownTime, "ShutDown" End Sub Sub ShutDown() ThisWorkbook.Close End Sub Sub Disable() On Error Resume Next Application.OnTime EarliestTime:=DownTime, Procedure:="ShutDown", Schedule:=False End Sub Sub CloseSave() Application.DisplayAlerts = False Sheets("Sheet1").Delete Application.DisplayAlerts = True ActiveWorkbook.Save End Sub Then in ThisWorkbook, i have this code: Private Sub Workbook_BeforeClose(Cancel As Boolean) Call CloseSave 'Disables Counted Shutdown Before closing Call Disable End Sub If i close the file manually, the code runs exactly as planned. BUT, if the timer expires, and "ShutDown" gets run, none of the things happen that should in "CloseSave". It DOES go through the code (I made sure in debug), but it doesnt do the code that is in it! For example, Sheet1 should get deleted. Debug mode confirmed it does go through this step, but it doesnt actually DO it... why not?? any ideas? Thanks |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Christchurch New Zealand
Posts: 1,030
|
your code over rides the before close event because your using code I would say when you close manually it runs the code but must skip the before close event when closing a workbook with code
I would just re write your code! Its like when you open another workbook with code it doesn't ask you if you want to enable macros on that workbook it just opens! [ This Message was edited by: brettvba on 2002-04-29 16:24 ] |
|
|
|
|
|
#3 |
|
Board Regular
Join Date: Feb 2002
Location: Stockton, California
Posts: 281
|
Is there anyway to prevent it from overriding? Re-write the code? what would you suggest to fix it....I'm clueless
|
|
|
|
|
|
#4 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Christchurch New Zealand
Posts: 1,030
|
so you want to delete sheet1 when the workbook closed each time leave the code as is and add the deletion of sheet1 code to shut down like this
Sub ShutDown() Application.DisplayAlerts = False Sheets("Sheet1").Delete Application.DisplayAlerts = True ActiveWorkbook.Save ThisWorkbook.Close End Sub also display alerts or anything like that will automatically revert back to true at the end of a macro. |
|
|
|
|
|
#5 |
|
Board Regular
Join Date: Feb 2002
Location: Stockton, California
Posts: 281
|
Ah yes, thanks very much for the help. I was thinking you meant rewrite the before close procedure...the solution was more simple
|
|
|
|
|
|
#6 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Christchurch New Zealand
Posts: 1,030
|
Not a problem
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|