[英]VBA function for Controls in Userform
I'm very new to VBA so I apologise if the question seems silly: I have set up a UserForm with some controls in it, and created a function called ResetMyField
as per below: 我是VBA的新手,所以我对这个问题看起来很傻表示歉意:我已经在其中设置了一些控件的UserForm,并按如下所示创建了一个名为
ResetMyField
的函数:
Function ResetMyField(MyField As Object)
If MyField = ProjectReference Then
'do something different and then
End If
MyField.Value = ""
End Function
When I call this function using ResetMyField(ProjectReference)
VBA comes out with a 424 error (Object Required). 当我使用
ResetMyField(ProjectReference)
调用此函数时,VBA出现424错误(需要对象)。 Should I be declaring MyField
as a different type of variable in the function? 我应该在函数中声明
MyField
为其他类型的变量吗?
Both the function and the point at which I call it are inside the Userform module. 函数和调用点都在Userform模块内部。
Any help would be much appreciated. 任何帮助将非常感激。
ResetMyField(ProjectReference)
, with the parentheses , tries to pass the default property of the ProjectReference
combobox into ResetMyField
. 带括号的
ResetMyField(ProjectReference)
尝试将ProjectReference
组合框的默认属性传递到ResetMyField
。 The default property of a combobox is Value
, and that is not an Object
, and ResetMyField
expects an Object
, hence the error ("Object Required"). 组合框的默认属性是
Value
,它不是Object
,并且ResetMyField
需要Object
,因此会出现错误(“ Object Required”)。
Remove the parentheses : 删除括号 :
ResetMyField ProjectReference
Also note that If MyField = ProjectReference Then
, again, tries to compare default properties of MyField
and ProjectReference
, which in case of comboboxes will mean If MyField.Value = ProjectReference.Value Then
. 还要注意,
If MyField = ProjectReference Then
,再次尝试比较MyField
和ProjectReference
默认属性,如果使用组合框,则将意味着If MyField.Value = ProjectReference.Value Then
。
If you want to know if MyField
is ProjectReference
, then it's 如果您想知道
MyField
是否为 ProjectReference
, MyField
If MyField Is ProjectReference Then
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.