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

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

b1g4l

New Member
Joined
Jul 9, 2007
Messages
8
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?
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,327
Messages
5,769,460
Members
425,550
Latest member
Bonebeast

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
Top