Macro to copy all sheets from source workb

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
I would like to copy each sheet with the data into the destination workbook and to create sheets if these do not exist

If the sheets already exist ... do they contain data ? .... is data to be overwritten OR added to ?
 
Upvote 0
The Sheets if they exits will contain data, which is to be overwritten
 
Upvote 0
Will the destination file contain any other sheets ?
If not, simply save a copy of source workbook like this

Code:
Sub SaveAsNewName()
    Dim newName As String, Source As Workbook
    ChDir "C:\Folder\SubFolder"    [COLOR=#006400][I]'this line is to specify where to find source file [/I][/COLOR]
    Set Source = Workbooks.Open(Application.GetOpenFilename)
    newName = Left(Source.Name, InStr(Source.Name, ".") - 1)
    newName = InputBox("amend name", "??", newName)
    Source.SaveAs Filename:=Source.Path & "\" & newName
    Source.Close False
End Sub


Error handling should be added to the above code
 
Last edited:
Upvote 0
The Destination workbook will not contain any other sheets

Many thanks for your help
 
Upvote 0

Forum statistics

Threads
1,223,703
Messages
6,173,973
Members
452,540
Latest member
haasro02

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