View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Auric__ Auric__ is offline
external usenet poster
 
Posts: 538
Default Macro to SAVE and EXIT from EXCEL

pcorcele wrote:

The heading says it all.
I want to save any open Excel files and then Close Excel
Thanks


Try this, edit to suit:

Sub SaveAllAndExit()
Dim Book As Workbook
For Each Book In Workbooks
'assumes Windows; Macs use ":" (or perhaps "/", no clue)
If InStr(Book.FullName, "\") < 1 Then
MsgBox "At least one workbook is new." & vbNewLine & _
"Manually save it before running this macro.", vbCritical
Exit Sub
End If
Next
For Each Book In Workbooks
If UCase$(Left$(Book.Name, 11)) < "PERSONAL.XL" Then
Book.Save
Book.RunAutoMacros xlAutoClose
End If
Next
Workbooks.Close
Application.Quit
End Sub

--
It's time to save the world from itself.