VBA - close all workbooks in macro.

whippler

New Member
Joined
Dec 13, 2002
Messages
15
I have a template that pulls in data from 37 other workbooks each week and calculates info with charts. My macro does not close all of the 37 workbooks automatically b/c each book prompts for "save changes? etc". Its not a big deal to click no 37 times real quick, but I would like my macro to close them all for me. Is there an easy way to write this in a loop so I dont have to hard code this for all 37 book file names?
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
just put
activeworkbook.close savechanges:=true

after each file used
i suppose thats the end of the loop
 
Upvote 0
Just to expand a little on the above.

activeworkbook.close savechanges:=true
>>This will close the workbook and save any changes.

activeworkbook.close savechanges:=false
>>This will close the workbook without saving any changes.

If you need any help in implementing the above, post your routine to the board so that we can see exactly what you are doing.
 
Upvote 0
As far as a loop goes, try the code below which will avoid you having to activate each workbook then close it with ActiveWorkbook:-<pre>
Public Sub CloseAllWorkbooks()
Dim wb As Workbook

For Each wb In Workbooks
wb.Close False ' Or True if you want changes saved
Next wb

End Sub</pre>
This message was edited by Mudface on 2002-12-15 14:23
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,256
Members
448,558
Latest member
aivin

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