Copy multiple sheets to a new workbook

sofas

Well-known Member
Joined
Sep 11, 2022
Messages
559
Office Version
  1. 2021
  2. 2019
Platform
  1. Windows
Welcome. I have a workbook consisting of several sheets. I want to copy all sheets to a new workbook ignoring only one sheet Sheet1, and save the new workbook in the same default path in xlsx format.
 
Save Sheet names, with the one exception, into a string with the pipe symbol as a separator.
Convert this into an array with Split, starting from the 2nd character (The first character is the pipe symbol).
Select/Copy the sheets from the array and save as a non macro workbook.

I assume that this is what you're referring to Dave.
If not, let us know please.

What you mentioned is also easy to do of course.
If you save your workbook, delete the sheet you don't want and save as a non macro enabled workbook.

This will work as you suggested, but you have to open the original again if you need it open.
Code:
Sub Another_Way()
Application.ScreenUpdating = False
ThisWorkbook.Save
Application.DisplayAlerts = False
    With ThisWorkbook
        Sheets("Sheet1").Delete
            .SaveAs ThisWorkbook.Path & "\" & Left(ThisWorkbook.Name, InStrRev(ThisWorkbook.Name, ".") - 1) & ".xlsx", FileFormat:=51
        .Close
    End With
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Thanks @jolivanes I understand all of that but you copy the sheets from the array and then what? It doesn't alter the original wb. They're not pasted to a new wb so how is the magic happening? Dave
 
Upvote 0
SaveAs will open the option of what to save your selection as if you do it manually. Here you shortcut it by telling it what to save it as.

If you want to see it, select a few sheets by holding down the Ctrl key while selecting the various sheets and click on the Office Button. If you select "SaveAs" you have the options of what to save it as.
 
Upvote 0
Well that is genius to take advantage of a built in feature... I had no idea that was possible. @ jolivanes thanks for your patient explanation. I was also wondering if you had any experience using this procedure to transfer sheets containing named ranges? The reason for the collection route that I coded is that I have found in the past that simply copying sheets and pasting them in another wb runs you into trouble if the sheets contain named ranges. Dave
 
Upvote 0
Dave
I very seldom work with named ranges but if they are worksheet scoped it should be no problem. I might be wrong here and someone with knowledge about it hopefully will let us know.
 
Upvote 0
Thanks for the link @jolivanes. I can't recall the exact error info related to named ranges that I was encountering when copy/pasting sheets but after messing around I found that using a collection to transfer the sheets resolved the issue.... so I've just stuck with it. Again, thanks for your code and explanation. Have a nice day. Dave
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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