如何处理用户窗体右上角的X按钮?
时间:2022-07-31 02:24:46
Q:经常有人会问,如何隐藏VBA用户窗体右上角的X关闭按钮?
A:使用API可以禁用或者移除用户窗体右上角的关闭按钮,但既然它已经存在,我们何不合理地利用它呢。
默认情况下,单击用户窗体右上角的X(关闭)按钮后,将卸载该用户窗体并从内存中清除。这样,其它代码将无法再与该用户窗体进行交互。此时,我们可以略微更改关闭按钮的功能,当用户单击该按钮时,隐藏用户窗体而不是彻底卸载它。
用户窗体模板如图1所示。
图1
代码如下:
Private SubbtnOK_Click()
Me.Hide
End Sub
Private SubbtnCancel_Click()
Me.Hide
End Sub
Private SubUserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
‘取消X按钮的默认行为
Cancel = True
Info
btnCancel_Click
End If
End Sub
Private SubInfo()
MsgBox “本用户窗体将被隐藏而不是被卸载,因此不会影响与本窗体相交互的代码.”
End Sub
标签:excel常用函数,excel常见问题,excel技巧,Excel教程
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
常见办公中word文字处理的5个技巧
2022-12-09 20:30:58
![](https://img.aspxhome.com/file/2023/2/34902_0s.jpg)
在Mac的Word 2011中选择书写样式!
2023-11-14 21:30:06
![](https://img.aspxhome.com/file/2023/7/23127_0s.jpg)
word怎样设置文字和段落的底纹
2022-01-25 05:47:32
如何随机选择excel单元格中的数据
2022-04-11 23:28:31
![](https://img.aspxhome.com/file/2023/0/36740_0s.gif)
word2013加载插件让数据运算功能更强大
2022-10-12 13:50:34
![](https://img.aspxhome.com/file/2023/4/29284_0s.jpg)
最简单快速输入直径符号Φ的方法
2022-02-20 19:27:31
excel怎么利用OFFSET函数定义名称
2023-06-03 13:42:59
![](https://img.aspxhome.com/file/2023/3/a142283_0s.gif)
Excel 2007工作表的保护设置步骤
2023-08-08 18:50:58
![](https://img.aspxhome.com/file/2023/0/43350_0s.gif)
Win10电脑显示器颜色不对怎么调整?
2023-11-18 12:19:41
![](https://img.aspxhome.com/file/2023/6/49766_0s.png)
word中各种线条样式输入方法大全
2023-09-25 17:26:16
![](https://img.aspxhome.com/file/2023/4/20854_0s.jpg)
word文档字符间距不一致怎么办
2022-06-21 08:41:51
![](https://img.aspxhome.com/file/2023/4/34114_0s.png)
Word最后一页空白页无论如何都删不掉
2023-12-14 03:29:42
![](https://img.aspxhome.com/file/2023/8/31718_0s.png)
Word工具栏消失怎么办
2022-08-16 06:16:57
Win10打开程序总会跳转到应用商店怎么回事?
2023-11-24 17:22:57
![](https://img.aspxhome.com/file/2023/5/52235_0s.jpg)
Win10蓝屏提示irql_not_less_or_equal的解决方法
2023-11-14 12:47:27
![](https://img.aspxhome.com/file/2023/4/49134_0s.png)
Word中MathType菜单消失怎么办
2023-01-27 02:08:30
![](https://img.aspxhome.com/file/2023/5/35155_0s.jpg)
word替换工具的使用方法介绍
2022-04-06 01:35:00
![](https://img.aspxhome.com/file/2023/0/24510_0s.jpg)
word怎样显示修改痕迹
2023-10-23 00:01:18
Word即点即输是什么
2023-12-09 20:59:29
![](https://img.aspxhome.com/file/2023/7/20767_0s.png)
Word中进行公文格式表格的操作方法
2022-10-29 15:52:50