Close the macro-containing workbook

awsumchillicrab

Board Regular
Joined
Jan 30, 2011
Messages
56
I store my macros in a spreadsheet "A", and so I have to manually open "A" in order to run my macro on another open spreadsheet. I guess that's acceptable since I don't want to add a quickaccess button.

But...after the macro finishes, I want spreadsheet "A" to close automatically.

I know a simple code like this would work:

ThisWorkbook.Close
End Sub

But here's the thing - the instruction to close the file and break any connection to the macro code is itself in the macro, by being before "End Sub".

That's just troubling to me. I feel like my macro isn't completely run and that it will be an issue somewhere, somehow. Is this just a purist pursuit, or is there a better way of achieving my goal?
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Out of curiosity, is there a reason you prefer to have a macro workbook rather than use excel's personal macro workbook and not have to worry about extra workbooks open?
 
Upvote 0
You have to end the sub somehow, and your code works already, right? Don't worry, VBA holds the sub in memory until it ends, even if the parent workbook is closed.
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,831
Members
452,946
Latest member
JoseDavid

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