Create a New Workbook and Save As? Help

MichaelRSnow

Active Member
Joined
Aug 3, 2010
Messages
409
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

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
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
 
Upvote 0
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?
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,858
Messages
6,121,956
Members
449,057
Latest member
FreeCricketId

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