VBA to copy all sheets to new workbook except one sheet

ziadh15

New Member
Joined
May 13, 2016
Messages
33
Hello

I want to copy all sheets in active workbook into a new workbook except one sheet called "Main".

I have written the code but it only copies the sheets that typed inside array.

I have a lot of hidden sheets so will take too much time naming each one.

--> I basically want to select all sheets except "Main" and copy them to new workbook.
Code:
Sub SaveAs()

Dim DataWorkbook As Workbook
Dim dt As String
Dim WorkbookName As String
Dim fileToSaveAs As Variant
Dim s As Worksheet

dt = Format(CStr(Now), "dd_mm_yyyy")
Set DataWorkbook = ActiveWorkbook


DataWorkbook.Sheets(Array("Instructions", "Collars")).Copy
WorkbookName = "c:\temp\Fishing Diagrams for StabilDrill_" & dt
fileToSaveAs = Application.GetSaveAsFilename(InitialFileName:=WorkbookName)

If fileToSaveAs <> False Then
ActiveWorkbook.SaveAs Filename:=fileToSaveAs, FileFormat:=52
End If

End Sub

DataWorkbook.Sheets(Array("Instructions", "Collars")).Copy
This is where I am stuck. The rest works fine :)
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Would this work?
Code:
Sub SaveAs()
Dim DataWorkbook As Workbook
Dim dt As String
Dim WorkbookName As String
Dim fileToSaveAs As Variant
Dim s As Worksheet
dt = Format(Date, "dd_mm_yyyy")
Set DataWorkbook = ActiveWorkbook
WorkbookName = "c:\temp\Fishing Diagrams for StabilDrill_" & dt.xlsm
fileToSaveAs = Application.GetSaveAsFilename(InitialFileName:=WorkbookName)
    If fileToSaveAs <> False Then
        DataWorkbook.SaveAs Filename:=fileToSaveAs, FileFormat:=52
        Application.DisplayAlerts = False
        ActiveWorkbook.Sheets("Main").Delete
        Application.DisplayAlerts = True
    End If
End Sub

Probably just as fast to manually do a saveas and then delet sheet "Main".
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

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