Create a New Workbook and Save As? Help

MichaelRSnow

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

Some videos you may like

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

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
379
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
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,397
Messages
5,511,111
Members
408,825
Latest member
Goncalves74

This Week's Hot Topics

  • Turn fraction around
    Hello I need to turn a fraction around, for example I have 1/3 but I need to present as 3/1
  • TIme Clock record reformatting to ???
    Hello All, I'd like some help formatting this (Tbl-A)(Loaded via Power Query) [ATTACH type="full" width="511px" alt="PQdata.png"]22252[/ATTACH]...
  • TextBox Match
    hi, I am having a few issues with my code below, what I need it to do is when they enter a value in textbox8 (QTY) either 1,2 or 3 the 3 textboxes...
  • Using Large function based on Multiple Criteria
    Hello, I can't seem to get a Large formula to work based on two criteria's. I can easily get a oldest value based one value, but I'm struggling...
  • Can you check my code please
    Hi, Im going round in circles with a Compil Error End With Without With Here is the code [CODE=rich] Private Sub...
  • Combining 2 pivot tables into 1 chart
    Hello everyone, My question sounds simple but I do not know the answer. I have 2 pivot tables and 2 charts that go with this. However I want to...
Top