Saving as new spreadsheet

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,392
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I am trying to create code to save my workbook, then save it again as a string entered in a textbox. I then want it to close the new workbook and reopen the original one. The workbook name can change so I can't use the name of the workbook as a reference point. I have this code so far:

Code:
Private Sub cmdNewTool_Click()
    With ActiveWorkbook
        .Save
        .SaveAs txtNewDoc.Text & ".xlsm"
        .Close
    End With
    Workbooks.Open Application.RecentFiles(1)
End Sub

This code saves it, saves it again as the new workbook, closes it, then reopens excel but doesn't open the last workbook that I saved the new workbook from. Can someone help me get the original workbook to open please?
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Why not simply

Code:
Private Sub cmdNewTool_Click()
ActiveWorkbook.SaveCopyAs Filename:="C:\Temp\" & txtNewDoc.Text & ".xlsm" 'change filepath to suit
End Sub
 
Upvote 0
or in the current directory

Code:
Private Sub cmdNewTool_Click()
ActiveWorkbook.SaveCopyAs Filename:=txtNewDoc.Text & ".xlsm"
End Sub
 
Upvote 0
Why not simply

Code:
Private Sub cmdNewTool_Click()
ActiveWorkbook.SaveCopyAs Filename:="C:\Temp\" & txtNewDoc.Text & ".xlsm" 'change filepath to suit
End Sub

Does the save copy as leave the current workbook open?
 
Upvote 0
That doesn't appear to be saving any additional copies.
 
Upvote 0
Yes !
What is in Textnewdoc ??
 
Last edited:
Upvote 0
Yes it is, my appologies, the files didn't appear but I tried again and then it did.
 
Upvote 0
How would I go about making some changes to the new document? Such as there are sheets that need the year incrementing in the name of the sheet and there are cells that contain the year that need incrementing too.

Thanks Michael
 
Last edited:
Upvote 0
Such as there are sheets that need the year incrementing in the name of the sheet and there are cells that contain the year that need incrementing too.
I thought that had been well covered in your previous threads !
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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