Userform.Show on a form button 无法识别 userform,出现错误 424 [英] Userform.Show on a form button will not recognize userform, getting Error 424

查看:47
本文介绍了Userform.Show on a form button 无法识别 userform,出现错误 424的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 VBA 知之甚少,但我正在尝试为 Excel 工作簿设计用户表单.这个想法是单击按钮,调出用户表单,输入信息,点击确定,然后您的信息格式正确并插入到工作表中.

I know very little about VBA, but I'm trying to design a userform for an excel workbook. The idea is click the button, bring up the userform, enter info, hit OK, and your info is formatted correctly and inserted into the worksheet.

我有 3 个用户表单,它们都可以正常工作,但是我创建的任何引用其中一个的宏都无法识别该特定用户表单的存在.

I have 3 userforms that all work fine, but any macro I create that references one of them just does not recognize that that particular userform exists.

我遇到问题的代码非常简单:

The code I'm having a problem with is pretty straightforward:

Private Sub LiquidFormButton_Click()

LiquidEntryUserform.Show

End Sub

编辑(更新):所以我尝试使用不同的名称创建一个新的用户表单.我将对象中的所有控件复制并粘贴到新的用户窗体上,更改了宏的名称以显示用户窗体,瞧,它可以工作了.但是,现在用户窗体本身不做任何事情,因为实际上没有任何控件背后有任何代码告诉它们该做什么.没关系,我只是从损坏的表单和 BOOM 中复制代码,现在它不起作用了.用户表单本身非常非常简单的编码中的某些东西阻止了它的显示,即使新的用户表单和损坏的用户表单实际上都做了除了显示之外他们需要做的所有事情.稍后我会在一些涉足之后发布完整的用户表单代码.谢谢!

Edit (Update): So I tried making a new userform, with a different name. I copied and pasted all of the controls from the object over to the new userform, changed the name of the macro to bring up the userform, and voila, it works. However, now the userform itself doesn't do anything because none of the controls actually have any codes behind them telling them what to do. That's fine, I'll just copy over the codes from the broken form and BOOM now it doesn't work. Soooo something in the very very simple coding within the userform itself is preventing it from being shown, even though the new userform AND the broken one both, in fact, do everything else they need to do besides show up. I'll post the full userform code up later on after some dabbling. Thank you!

推荐答案

你应该像这样实例化"表单

You should 'instantiate' the form like so

Private Sub LiquidFormButton_Click()

    Dim liquid as LiquidEntryUserform ' define a liquid var of the correct type
    Set liquid = new LiquidEntryUserform ' create the Form
    liquid.Show  'show it

    ' here you can still access variables 
    ' on the form
    If liquid.TextBox1.Text = "700" Then 
       'do things
    End if

End Sub

我的项目如下所示:

您可以使用对象浏览器(查看|对象浏览器或点击 F2)来查找您项目中的表单和类:

You can use the Object Browser (View|Object Browser or hit F2) to find the Forms and Classes you have in your project:

这篇关于Userform.Show on a form button 无法识别 userform,出现错误 424的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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