ActiveWorkbook.Close Failure

ajorlov

New Member
Joined
Feb 3, 2005
Messages
29
I have consistently used ActiveWorkbook.Close in my macros without problem to both close other workbooks and to close the workbook in which the code itself is contained. However, suddenly that function still works when it is being used to close a workbook other than the one containing the code but it no longer will close the workbook that contains it.

Around the time this problem emerged (several days ago) I was having a SQL Server issue, in which my trial copy expired and I had to install a new version. This is the only thing I can think of that has changed on my machine.

Thoughts? Thanks
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
My first thought would be not to use ActiveWorkbook in the first place.

If you want to deal with the workbook with the code in it use ThisWorkbook.

If you want to deall with others trying explicitly naming them.

If you are opening workbooks then create references to them when you open them and then use them when you want to close them.
Code:
Dim wbThis As Workbook
Dim wbOpen As Workbook
 
    Set wbThis = ThisWorkbook ' create reference to workbook containing code
    Set wbOpen  = Workbooks (C:\WorkBookToOpen.xls)
    ' code
 
    ' now lets close that workbook you opened
    wbOpen.Close
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,928
Members
452,366
Latest member
TePunaBloke

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