Frank Freese
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
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
The code used is
Sub closeme()
ThisWorkbook.Close
End Sub
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
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.
I don't understand your question... sorry.
ASKER
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.GetS aveAsFilen ame, FileFormat:=52
End If
ActiveWorkbook.Close
ActiveWorkbook.Quit
End Sub
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.GetS
End If
ActiveWorkbook.Close
ActiveWorkbook.Quit
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect! Thank you - I was close (almost)
ASKER
great job - thank you
You're welcome and thanks for the grade.
jppinto
jppinto
Close-Me.xls