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
Frank FreeseAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
jppintoConnect With a Mentor Commented:
Like this should do it:

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
End If
Application.Quit
End Sub
0
 
Ardhendu SarangiSr. Project ManagerCommented:
Here's the code -
Close-Me.xls
0
 
Ardhendu SarangiSr. Project ManagerCommented:
The code used is


Sub closeme()
ThisWorkbook.Close
End Sub
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
jppintoCommented:
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

0
 
Frank FreeseAuthor Commented:
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)
0
 
jppintoCommented:
You can make a .SaveAs or .Save

I don't understand your question... sorry.
0
 
Frank FreeseAuthor Commented:
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
0
 
Frank FreeseAuthor Commented:
Perfect! Thank you - I was close (almost)
0
 
Frank FreeseAuthor Commented:
great job - thank you
0
 
jppintoCommented:
You're welcome and thanks for the grade.

jppinto
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.