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

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Forum statistics

Threads
1,213,497
Messages
6,114,002
Members
448,543
Latest member
MartinLarkin

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