1、类模块中创建名为AppEventHandle的对象,属性选择2 - PublicNotCreateable
'文档关前操作
Private Sub app_DocumentBeforeClose(ByVal Doc As Document, Cancel As Boolean)
intResponse = MsgBox("是否将更改保存到“"+Doc.Name+"”中?", vbYesNoCancel)
'取消关闭文档
If ThisDocument.intResponse = vbCancel Then
Cancel = True
End If
'保存并关闭文档
If ThisDocument.intResponse = vbYes Then
ActiveDocument.Close wdSaveChanges
End If
'不保存文档并关闭文档
If ThisDocument.intResponse = vbNo Then
ActiveDocument.Close wdDontSaveChanges
End If
End Sub
2、ThisDocument
添加全局变量
Public intResponse As Integer '用来接收关闭时选择的操作的参数值
Public app As New AppEventHandle
'注册Applicant事件
Sub Register_Event_Handler()
On Error Resume Next
Set app.app = Application
End Sub
3、Document_Close方法中处理代码去掉
本文来源:https://www.wddqw.com/doc/491dae069b6648d7c0c74635.html
正在阅读:
VBA禁用Word自带保存提示处理方法(个人总结)01-01
2020最新人教部编版二年级语文下册第一单元复习知识点01-01
精选廉洁自律承诺书大全7篇01-01
财务机器人对会计从业人员的影响分析01-01
周敦颐《爱莲说》加点字解释与课文翻译01-01
作文 邻家小妹01-01
肖申克的救赎影视欣赏论文01-01
我是妈妈的小棉袄01-01