VBA - Let user save as file and close

jccnz

New Member
Joined
May 28, 2019
Messages
13
Hi There,
I created a button to allow user on mouse click save as file on their location but I want to close the workbook after save as.
are there any way to close after save as?
Code:
Private Sub Image1_Click()
Dim result As Variant
Dim activebook As Workbook
Application.DisplayAlerts = False

ThisWorkbook.Sheets("OpenOrder").Copy
result = Application.GetSaveAsFilename(FileFilter:="Excel File (*.csv), .csv", Title:="Save Excel")

If result <> 0 Then
ActiveWorkbook.SaveAs Filename:=result, FileFormat:=xlCSV
Application.DisplayAlerts = True

'ActiveWorkbook = "result" & ".csv"
'If Workbook_Name <> False Then
'ActiveWorkbook.SaveAs Filename:=Workbook_Name

ActiveWorkbook.Close savechanges:=False
End If
End Sub
 
Last edited by a moderator:

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Like this?

VBA Code:
Private Sub Image1_Click()
Dim result As Variant
Dim activebook As Workbook
Application.DisplayAlerts = False

ThisWorkbook.Sheets("OpenOrder").Copy
result = Application.GetSaveAsFilename(FileFilter:="Excel File (*.csv), .csv", Title:="Save Excel")

If result <> 0 Then
ActiveWorkbook.SaveAs Filename:=result, FileFormat:=xlCSV
Application.DisplayAlerts = True

'ActiveWorkbook = "result" & ".csv"
'If Workbook_Name <> False Then
'ActiveWorkbook.SaveAs Filename:=Workbook_Name

ActiveWorkbook.Close savechanges:=False
End If
ThisWorkbook.Close savechanges:=False
End Sub
 
Upvote 0
Hello again, hope you are well where you are.
when the save as dialogue box pop up, the file usually given name as "Book1.csv", and users will normally save as in repeated location with the same file name.
All I want is letting users to save and replace the old.
Thanks
 
Upvote 0
When I save as with the same name the macro just continues and the workbook closes. What's happening there?
 
Upvote 0
I have tested couple of time, yes you are right it closed, I will check w/ the user again. ;)
Many thanks
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,276
Members
449,075
Latest member
staticfluids

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