Any idea of how to close list of workbooks using VBA ?

xlhelp15

Board Regular
Joined
Sep 12, 2014
Messages
53
Hello Genius - Is there a way to close list of workbooks using VBA ? Have tried the way of Workbooks("sample1").close but it closed only the sample1 WB. I need to close Sample1, Sample5, Sample12 in a row when I click the command button.

Thank you for considering my request.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Captain_Conman

Board Regular
Joined
Jun 14, 2018
Messages
54
Rich (BB code):
Workbooks("Sample1").Close
Workbooks("Sample5").Close
Workbooks("Sample12").Close

If you list them in a row like this, they will all close when you hit the command button
 
Last edited:

xlhelp15

Board Regular
Joined
Sep 12, 2014
Messages
53
Thank you, Captain.

But it works only when those sample workbooks are in open status.

It needs to close the file if it exists, otherwise no action to perform.

Any help here ?
 
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,193
Messages
5,768,770
Members
425,492
Latest member
blueexcel123

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