Closing Excel Application using VBA

前端 未结 8 1238
忘了有多久
忘了有多久 2020-11-29 04:44

I have used the following without success. The active workbook closes, indeed, but the excel window remains open.

Application.ActiveWindow.Close SaveChanges:         


        
8条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-29 05:07

    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.

提交回复
热议问题