从 Excel 用户表单返回值或取消 [英] Returning a value or Cancel from Excel userform

查看:38
本文介绍了从 Excel 用户表单返回值或取消的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个子程序,它调用一个用户表单来显示,如果用户没有点击我的取消按钮,我只想继续.我不想将所有其他子调用放在用户表单中.

I have a sub that calls a userform to show and would only like to proceed if the user didn't click my Cancel button. I don't want to put all my other sub calls within the userform.

是否可以让用户表单返回一个值或一种检查用户是否单击特定按钮的方法?

Is it possible to have a userform return a value or a way to check if the user clicked a particular button?

我想我可以使用全局变量,但想知道是否可以在用户表单之间传递信息.

I suppose I can use a global variable, but was wondering if I could pass things to and from a userform.

推荐答案

我更喜欢使用属性.

在您的用户表单中

Private m_bCancel As Boolean

Public Property Get Cancel() As Boolean
    Cancel = m_bCancel
End Property

Public Property Let Cancel(ByVal bCancel As Boolean)
    m_bCancel = bCancel
End Property

取消按钮代码

Private Sub cmdCancel_Click()
    Me.Cancel=True
    Me.Hide
End Sub

像这样从外部调用 userForm

Call the userForm from outside like this

sub loadForm()

dim frm 

set frm= new UserForm1
frm.show

if frm.Cancel then
   Msgbox "Cancelled"
end if

End Sub

这篇关于从 Excel 用户表单返回值或取消的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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