关闭一个用户表单卸载我不工作 [英] Closing a Userform with Unload Me doesn't work

查看:89
本文介绍了关闭一个用户表单卸载我不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果用户点击了提交按钮并执行了操作,我需要使用VBA关闭Excel用户窗体。

I need to close an Excel userform using VBA when a user has clicked a submit button and operations have been carried out.

如何从本身关闭Userform ?

How can I close a Userform from itself?

我已经尝试过,但是它返回了361错误。

I have tried this but it returns a 361 error.

Unload Me


推荐答案

根据顶级答案,在按钮控件后面的代码中使用以下代码。

As specified by the top answer, I used the following in the code behind the button control.

Private Sub btnClose_Click()
    Unload Me
End Sub

这样做,它不会尝试卸载控件,而是卸载用户按钮控件所在的窗体。即使从用户表单上的控件调用,Me关键字也是指用户表单对象。如果您使用此技术遇到错误,可能有几个可能的原因。

In doing so, it will not attempt to unload a control, but rather will unload the user form where the button control resides. The "Me" keyword refers to the user form object even when called from a control on the user form. If you are getting errors with this technique, there are a couple of possible reasons.


  1. 您可以在错误的地方(如
    单独的模块)

  1. You could be entering the code in the wrong place (such as a separate module)

您可能使用的是旧版本的Office。我正在使用Office 2013.我注意到VBA随着时间的推移而改变。

You might be using an older version of Office. I'm using Office 2013. I've noticed that VBA changes over time.

根据我的经验,使用的DoCmd ....方法更具体到MS Access中的宏功能,但在Excel VBA中不常用。

From my experience, the use of the the DoCmd.... method is more specific to the macro features in MS Access, but not commonly used in Excel VBA.

在正常情况下(开箱即用) )条件,上面的代码应该正常工作。

Under normal (out of the box) conditions, the code above should work just fine.

这篇关于关闭一个用户表单卸载我不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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