Workbook not closing

b1g4l

New Member
Joined
Jul 9, 2007
Messages
8
I am having an unusual issue. I have two workbooks open and simply want to close both without saving either of them. One workbook is a UI and the other a database that the user never sees. If I click the 'x' in the top right, it works fine but if I try to close via VBA code, the database workbook does not close.

From the UI workbook I have:
Code:
Private Sub Run_Shell_Command()
    currentDir = ActiveWorkbook.Path     'Directory of current workbook
    batchPath = currentDir & "\update.bat"     'Full path to batch file
    'Run batch file with argument of current directory
    Shell batchPath & " " & currentDir, vbNormalFocus
    'Close workbook so that batch file can overwrite files
    ActiveWorkbook.Close
End Sub

I also have a Workbook_BeforeClose method that is as follows:
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Workbooks("DB.xls").Saved = True
    Workbooks("DB.xls").Close
    ThisWorkbook.Saved = True
End Sub

No error message or anything. The workbook just doesn't close when I try to close it via VBA code. Any ideas?
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
If I take out the Workbook_BeforeClose method, the VBA code works. Is there anyway I can skip through that method but keep it so it runs when the user exits via the 'x' in the top right?
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,552
Members
449,088
Latest member
davidcom

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