Create a New Workbook and Save As? Help

MichaelRSnow

Active Member
Joined
Aug 3, 2010
Messages
382
Hi Help needed.

Been reviewing code for ages now and none seem to be that simple, I'm trying to, via a Command Button, Copy & Paste Values of Sheet1 in the existing workbook to a New Workbook and then open SAVE AS so it can be saved where the user wants it to be and called what ever they want to call it?

If anyone has some code for this it will be very much appreciated?
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
Hi

the code executed by the button could look like this:

Code:
Sub copy_sheet1()
 
Dim ws As Worksheet
 
Set ws = Worksheets("Sheet1")  'amend as required
 
Workbooks.Add
ws.UsedRange.Copy
Activesheet.Range("A1").PasteSpecial xlPasteValues
 
With Application.FileDialog(msoFileDialogSaveAs)
    .InitialFileName = Application.DefaultFilePath
    .AllowMultiSelect = False
    If .Show = -1 Then .Execute
End With
End Sub
 

MichaelRSnow

Active Member
Joined
Aug 3, 2010
Messages
382
Works great, 1 small thing...what if some of the cells were hidden in the orginal workbook, this current method doesn't keep the copied cells hidden. Can this be achieved?
 

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
If you didn't want to copy the hidden cells you could do this:

Code:
Sub copy_sheet1()
 
Dim ws As Worksheet
 
Set ws = Worksheets("Sheet1")  'amend as required
 
Workbooks.Add
ws.UsedRange.SpecialCells(xlCellTypeVisible).Copy
Activesheet.Range("A1").PasteSpecial xlPasteValues
 
With Application.FileDialog(msoFileDialogSaveAs)
    .InitialFileName = Application.DefaultFilePath
    .AllowMultiSelect = False
    If .Show = -1 Then .Execute
End With
End Sub

or if you want to copy them and have them hidden then try this (note I doubt whether you'll be able to do this if you have any merged cells on the sheet):

Code:
Sub copy_sheet1()
 
Dim ws As Worksheet
 
Set ws = Worksheets("Sheet1")  'amend as required
 
Workbooks.Add
ws.Cells.Copy
Activesheet.Range("A1").PasteSpecial
Activesheet.Range("A1").PasteSpecial xlPasteValues
 
With Application.FileDialog(msoFileDialogSaveAs)
    .InitialFileName = Application.DefaultFilePath
    .AllowMultiSelect = False
    If .Show = -1 Then .Execute
End With
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,132,996
Messages
5,656,295
Members
418,293
Latest member
michaelkellyfrombelfast

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
Top