简体   繁体   English

VBA Excel:从模块中的窗体中调用子

[英]VBA Excel: Call sub in form from module

I want to call a function in a form from a function in a modul 我想从模块中的函数中调用某种形式的函数

So I defined the function Init_StockForm() in the form (which is called Form): 因此,我以表单(称为表单)的形式定义了函数Init_StockForm():

    Public Sub Init_StockForm()

      MsgBox ("Bla")

    End Sub

I call that function in the module as follows: 我在模块中按以下方式调用该函数:

    Form.Init_StockForm

but this results in a Runtime error 91 但这会导致运行时错误91

So what's wrong here? 那这怎么了? Thanks form help 感谢表格帮助

make a new instance of your form (VBA is object oriented Programming Language) 制作表单的新实例(VBA是面向对象的编程语言)

module: 模块:

Private Sub callFormSub()
Dim myForm As New UserForm1
myForm.subInUserForm
End Sub

Form: 形成:

Public Sub subInUserForm()
MsgBox "BLA"
End Sub

谢谢您的答复今天,我发布的解决方案也可以运行(:/),原因可能是安装上的错误,因为宏在其他函数中也显示出非常奇怪的行为,但是稍后我将在另一篇文章中进行发布。如果我解决不了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM