关闭窗体前提示用户

下面的示例演示如何提示用户验证表单是否应关闭。

Private Sub Form_Unload(Cancel As Integer) 
 If MsgBox("Are you sure that you want to close this form?", vbYesNo) = vbYes Then 
 Exit Sub 
 Else 
 Cancel = True 
 End If 
End Sub

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。