互联网技术 · 2024年2月23日

实现Excel自定义关闭按钮的代码

这篇文章主要介绍了Excel自定义关闭按钮实现代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

遇到过这样一个需求,是在excel关闭的时候,不要excel本身的保存窗口,只用自定义的.

这个的需要第一,是点击关闭时候触发,

第二;触发后,不能还是弹出那个窗口

第三:取消后,要能停止程序

为了弄这个摸索了很久,最后总算通过结合,找出了解决办法:

先执行

Private Sub Workbook_BeforeClose(Cancel As Boolean)
If C_Msg.PostA(“Com_Err023”, , True, 1) = vbOK Then

Dim xxx As String
xxx = “Yes”
Cancel = False
Else
Dim sss As String
sss = “No”
Cancel = True
End If
End Sub

再执行

Sub Auto_Close()

ThisWorkbook.Saved = True
If Application.Workbooks.Count = 1 Then
Application.Quit
End If
ThisWorkbook.Close False
End Sub

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

来源:脚本之家

链接:https://www.jb51.net/article/201311.htm

OpenMagic API

Need more than content? Move into the product flow.

If you are here for model access, pricing, developer docs, or the future API console, the dedicated product path now lives on api.openmagic.ai.

登录免费注册