Closing Excel Application using VBA
I think your problem is that it's closing the document that calls the macro before sending the command to quit the application.
Your solution in that case is to not send a command to close the workbook. Instead, you could set the "Saved" state of the workbook to true, which would circumvent any messages about closing an unsaved book. Note: this does not save the workbook; it just makes it look like it's saved.
ThisWorkbook.Saved = True
and then, right after
Application.Quit
To avoid the Save prompt message, you have to insert those lines
Application.DisplayAlerts = False
ThisWorkbook.Save
Application.DisplayAlerts = True
After saving your work, you need to use this line to quit the Excel application
Application.Quit
Don't just simply put those line in Private Sub Workbook_Open() unless you got do a correct condition checking, else you may spoil your excel file.
For safety purpose, please create a module to run it. The following are the codes that i put:
Sub testSave()
Application.DisplayAlerts = False
ThisWorkbook.Save
Application.DisplayAlerts = True
Application.Quit
End Sub
Hope it help you solve the problem.