首页 > 解决方案 > VBA Before close event

问题描述

there is 2 events in my code i.e Before close,before save. in before save condition there are conditions to be filled before saving, else it wont allow to save. now while triggering before close, it will popup for save, dontsave, cancel message box. when selecting save, it will call before save function and it throws error message as like before save function. but after that file is closed.

    Public Sub Workbook_BeforeClose(Cancel As Boolean)

Exit Sub

End Sub

标签: excelvba

解决方案


我想我误解了你试图描述的内容,但看看我下面的代码是否可以帮助你。

Public Sub Workbook_BeforeClose(Cancel As Boolean)

        Select Case MsgBox("Select what do you want", vbYesNoCancel + vbExclamation, "Atention")
            Case vbYes
                Call Workbook_BeforeSave(True, False)
            Case vbNo
                Application.Quit
            Case vbCancel
                Cancel = True
        End Select

 Exit Sub

推荐阅读