Reset/stop 'Auto_Close' sub midway, so workbook is not closed?

Vantom

Board Regular
Joined
Feb 28, 2014
Messages
65
Is it possible to reset an 'Auto_Close' sub if a condition is met midway, so that the workbook stays open?
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Is it possible to reset an 'Auto_Close' sub if a condition is met midway, so that the workbook stays open?
Post your auto_close sub and explain the condition that must be met to cancel it.
 
Upvote 0
The if statement is in the 'AutoBackup' sub.
Code:
Sub Auto_Close()
    OptimizeVBA True
'Delete:
    Call DeleteSheets
        With Cells: .Delete Shift:=xlUp: End With
'Call AutoBackup:
    Call AutoBackup
    
    OptimizeVBA False
'Save/Saved:
    With Workbooks("CheckReportNumbers.xlsm"): .Save: .Saved = True: End With
End Sub
 
Upvote 0
The if statement is in the 'AutoBackup' sub.
Code:
Sub Auto_Close()
    OptimizeVBA True
'Delete:
    Call DeleteSheets
        With Cells: .Delete Shift:=xlUp: End With
'Call AutoBackup:
    Call AutoBackup
    
    OptimizeVBA False
'Save/Saved:
    With Workbooks("CheckReportNumbers.xlsm"): .Save: .Saved = True: End With
End Sub
I don't see anything in what you posted that closes a workbook. And there are other modules involved that you are not showing. Keep in mind that we know nothing about what you want to accomplish or other code that may be involved.
 
Upvote 0
I close the workbook, and the 'Sub Auto_Close()' runs, and I want the sub/s to be reset using code, if a condition is met.

If I set a breakpoint manually, I can click reset manually when the sub breaks and then I can click 'cancel' when the 'save'/'don't save'/'cancel' prompt asks. I'm wondering if the same can be done automatically using code?
 
Last edited:
Upvote 0
I'm guessing that your Auto_Close routine is being called by the Workbook_BeforeClose event. IF you Make Auto_Close a function, it can return the Cancel value for the BeforeClose to process.

What code is in your BeforeClose event?
 
Upvote 0
Found a solution, run a batch file to open the workbook if the condition is met!
Code:
Sub Auto_Close()    
    If 2 + 2 = 4 Then Call Shell("C:\Users\X\Documents\OpenBook1.bat")
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,069
Messages
6,128,608
Members
449,460
Latest member
jgharbawi

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