在VBA中关闭表单时执行代码(Excel 2007) [英] Execute code when form is closed in VBA (Excel 2007)

查看:663
本文介绍了在VBA中关闭表单时执行代码(Excel 2007)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户使用窗口右上角的x按钮关闭表单时,我想执行一些代码(打开excel电子表格时,我已经填写了表单,并隐藏Excel,我想退出表单关闭后,或者至少显示excel,以便用户可以手动退出)

I would like to execute some code when a user closes a form using the x button in the top right corner of the window (I have the form load when the excel spreadsheet is opened, and it hides Excel. I want to exit excel once the form is closed, or at least show excel again so the user may exit it manually)

查看表单属性,Unload属性不存在,也不存在我可以弄清楚如何使表单关闭时执行的功能。

Looking at the form properties, the Unload property is not present, nor am I able to figure out how to make a function which executes when the form is closed.

不幸的是,在VB中编码这不是一个选项,它必须是VBA。

Unfortunately, coding this in VB is not an option, it must be VBA.

我知道取消隐藏Excel或直接退出的代码,只是不能将其绑定到卸载事件。

I'm aware of the code needed to unhide Excel or quit it outright, just not how to tie it to the unload event.

推荐答案

一位同事能够提供答案,其中包括其他人的示例

A colleague was able to provide the answer, including example here for everybody else

Private Sub userform_terminate()

    'Code goes here

End Sub

这篇关于在VBA中关闭表单时执行代码(Excel 2007)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆