save as, closes master sheet then reopens the new saved worksheet

excelnoobhere

Board Regular
Joined
Mar 11, 2019
Messages
61
I have the Following button code that saves my workbook at a desired location (Save As) with a desired name without including the pages "Main" and template".

Right after I save the copy, I have another button that when clicked, it closes my "Master" workbook without any changes but keeps excel open without any sheets.

I'd like to be able to to click the close button (CloseWorkbook()) and automatically closes my "master" workbook and opens up the workbook I just saved. I need to be able to open it no matter where it was saved or any given name.

I'm guessing these have to be combined into one step

Thanx in advance

'save the folader at a desired location
Sub SaveWorkbook()


Dim ws As Worksheet
Dim savename As String
Dim cnt As Long
Dim arrSheets()


With ActiveWorkbook
ReDim arrSheets(1 To .Sheets.Count)
For Each ws In .Sheets
Select Case ws.Name
Case "Main", "template"
' do nothing
Case Else
cnt = cnt + 1
arrSheets(cnt) = ws.Name
End Select
Next ws
ReDim Preserve arrSheets(1 To cnt)
' copy sheets to new workbook
.Sheets(arrSheets).Copy
End With

MsgBox ("You will now be prompted to save your file, after naming the file click 'Save'") 'Notifies User
savename = Application.GetSaveAsFilename(fileFilter:="Exel Files (*.xlsx), *.xlsx")
If savename <> "False" Then
' save and close new workbook
With ActiveWorkbook
.SaveAs Filename:=savename, FileFormat:=51 'Something iswrong
.Close SaveChanges:=False
End With
End If




End Sub


Sub CloseWorkbook()
MsgBox ("Open the file that was just saved") 'Notifies User
ThisWorkbook.Close Saved = True


End Sub
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Code:
.Close SaveChanges:=False
If you comment this line out, or delete it, wouldn't that leave your new workbook open?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,254
Members
452,624
Latest member
gregg777

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