VBA/Macro to select specific worksheets and save them as separate files

krodriguez

Board Regular
Joined
Jul 11, 2012
Messages
119
Hello - I have file that is saved as binary .xlsb and have several tabs. I need to be able to select just a few of the worksheets(tabs) and save them as separate versions. Anyone out there with a code that can assist? Thanks!
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
This will get you started.
Code:
Sub SaveSheetsAsFiles()
Dim SheetsToSave
SheetsToSave = Array("Sheet1", "Sheet3", "Sheet5") 'change tab names to suit
Application.ScreenUpdating = False
For Each sht In Sheets(SheetsToSave)
    sht.Copy
    'file location is same as workbook the code is in. Change to suit
    'file format is .xlsm - change to suit
    ActiveWorkbook.SaveAs Filename:=sht.Name & ".xlsm", FileFormat:=52
Next sht
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Thanks Joe this works. But how can I save them in one excel instead of 3 different ones? and also If I want to add more subsets like ("Sheet1", "Sheet3", "Sheet5") in 1 file, then "Sheet6", "Sheet7", "Sheet8") in a second file...how can this be done?
 
Last edited:
Upvote 0
Your OP title and text said you want to save the sheets as "separate files" and "separate versions", respectively. A bit more care in describing what's wanted would save time all around.

To save the sheets to a new (single) workbook, just follow the posted code for the first sheet, then copy subsequent sheets to the workbook created with the first sheet.
 
Upvote 0
Thanks. Getting an error looks like my function is incorrect to run both macros at once. Can you assist? sorry as you can see trying to learn vba


Sub Run_All_Macros()


Call SaveSheetsAsFiles1
Dim SheetsToSave
SheetsToSave = Array("Rainbow", "RLN-Net Realization RLN-Red Rev RLN-COGS", "RLN-Logistics", "RLN-R&D", "RLN-Selling RLN-Administrative", "RLN-Advertising", "RLN-Sales Promo") 'change tab names to suit
Application.ScreenUpdating = False
For Each sht In Sheets(SheetsToSave)
sht.Copy
'file location is same as workbook the code is in. Change to suit
'file format is .xlsm - change to suit
ActiveWorkbook.SaveAs Filename:=sht.Name & ".xlsm", FileFormat:=52
Next sht
Application.ScreenUpdating = True
End Sub


Call SaveSheetsAsFiles2
Dim SheetsToSave
SheetsToSave = Array("Neocell", "NC-Net Realization", "NC-Red Rev", "NC-COGS NC-Logistics", "NC-R&D", "NC-Selling", "NC-Administrative", "NC-Advertising", "NC-Sales Promo") 'change tab names to suit
Application.ScreenUpdating = False
For Each sht In Sheets(SheetsToSave)
sht.Copy
'file location is same as workbook the code is in. Change to suit
'file format is .xlsm - change to suit
ActiveWorkbook.SaveAs Filename:=sht.Name & ".xlsm", FileFormat:=52
Next sht
Application.ScreenUpdating = True
End Sub


End Sub
 
Upvote 0

Forum statistics

Threads
1,223,713
Messages
6,174,043
Members
452,542
Latest member
Bricklin

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