Macro to SAVE and EXIT from EXCEL

P

pcorcele

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

Auric__

pcorcele said:
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
 
A

Abhijeet Gudur

Option Explicit
Sub Save_close()
'Whichever file contains this code will remain open in the end
Dim wb As Workbook

For Each wb In Workbooks
If wb.Name = ThisWorkbook.Name Then
'do nothing
Else
wb.Close savechanges:=True
End If
Next wb

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top