Link to home
Start Free TrialLog in
Avatar of Frank Freese
Frank FreeseFlag for United States of America

asked on

Macro to Close Excel

Experts,
I would like to create a command button that runs a macro that when selected closes Excel, asking to save changes, if changes have been made.
The name of my Workbook is Monthly
Avatar of Ardhendu Sarangi
Ardhendu Sarangi
Flag of United States of America image

Here's the code -
Close-Me.xls
The code used is


Sub closeme()
ThisWorkbook.Close
End Sub
Is this what you want?
Dim strMsg As String
Dim intQ As String

strMsg = "Do you want to save changes?"
intQ = MsgBox(strMsg, vbQuestion + vbYesNo, "Save changes?")

If intQ = vbYes Then
    ActiveWorkbook.SaveAs Filename:=Application.GetSaveAsFilename, FileFormat:=52
End If
ActiveWorkbook.Close

Open in new window

Avatar of Frank Freese

ASKER

jp: close...real close...I like MsgBox...If the user wants to save changes can I execute a ActiveWorkbook.Save, ActiveWorkbook.Close, and ActiveWorkbook.Quit (not Activeworkbook.SaveAs)
You can make a .SaveAs or .Save

I don't understand your question... sorry.
Here's my code. My objective would be to save the file, close the program and exit excel:

Sub CloseExcel()

Dim strMsg As String
Dim intQ As String

strMsg = "Do you want to save changes?"
intQ = MsgBox(strMsg, vbQuestion + vbYesNo, "Save changes?")

If intQ = vbYes Then
ActiveWorkbook.Save Filename:=Application.GetSaveAsFilename, FileFormat:=52

End If
ActiveWorkbook.Close
ActiveWorkbook.Quit
End Sub
ASKER CERTIFIED SOLUTION
Avatar of jppinto
jppinto
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Perfect! Thank you - I was close (almost)
great job - thank you
You're welcome and thanks for the grade.

jppinto