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?
 
I use the save copy as and it make a new copy of the file and then I was going to open the file, make the changes then close it. I have this so far
Code:
Private Sub cmdNewTool_Click()
Dim newDoc As String
    newDoc = txtNewDoc.Text & ".xlsm"
    
    ActiveWorkbook.SaveCopyAs Filename:=txtNewDoc.Text & ".xlsm"

but I wasn't sure of the syntax to open the file.
 
Upvote 0

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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