Code to close variours files

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,601
Office Version
  1. 2021
Platform
  1. Windows
I have written code to close several workbooks, which is shown below

The code closes all the workbooks except the the workbooks named Volvo. The full names are volvo_Service_Sales and Volvo_parts_sales

It would be appreciated if you could assist

Sub close_Files()
For Each wb In Workbooks
If wb.Name Like "*93_94.xls" Then wb.Close True
For Each wb1 In Workbooks

If wb1.Name Like "volvo*" Then wb1.Close True

For Each wb2 In Workbooks

If wb2.Name Like "Niss*" Then wb2.Close True
For Each wb3 In Workbooks

If wb3.Name Like "Volpe*" Then wb3.Close True
Next

Next
Next
Next

End Sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Maybe you need:

Code:
If LCase(wb1.Name) Like "volvo*" Then wb1.Close True

You could also try:

Code:
Sub close_Files()
    Dim wb As Workbook
    For Each wb In Workbooks
        If wb.Name Like "*93_94.xls" Or LCase(wb.Name) Like "volvo*" Or wb.Name Like "Niss*" Or wb.Name Like "Volpe*" Then wb.Close True
    Next wb
End Sub
 
Upvote 0
Hi Andrew

Thanks for the help, much appreciated

Regards

Howard
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,716
Members
452,939
Latest member
WCrawford

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