在 VBA 中调用子程序
这是我的简化脚本:
Sub SomeOtherSub(Stattyp As String)
'Daty and the other variables are defined here
CatSubProduktAreakum(Stattyp, Daty + UBound(SubCategories) + 2)
End Sub
Sub CatSubProduktAreakum(Stattyp As String, starty As Integer)
'some stuff
End Sub
CatSubProduktAreakum 的调用被标记为红色作为“语法错误”。我不明白这个错误。这是一个带有两个参数的简单子例程调用。为什么VBA不接受调用?
This my simplified script:
Sub SomeOtherSub(Stattyp As String)
'Daty and the other variables are defined here
CatSubProduktAreakum(Stattyp, Daty + UBound(SubCategories) + 2)
End Sub
Sub CatSubProduktAreakum(Stattyp As String, starty As Integer)
'some stuff
End Sub
The call of CatSubProduktAreakum is marked red as a "syntax error". I don't understand the error. It is a simple sub-routine call with two arguments. Why does VBA not accept the call?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试 -
至于原因,这是来自 MSDN 通过这个问题 - 什么Call关键字在VB6中做什么?
Try -
As for the reason, this from MSDN via this question - What does the Call keyword do in VB6?
对于仍然阅读本文的人,另一个选择是简单地省略括号:
Call
关键字在 VBA 中实际上只是为了向后兼容,实际上并不是必需的。但是如果您决定使用
Call
关键字,那么您必须更改语法以适应。两者都会做完全相同的事情。
话虽这么说,但在某些情况下,可能需要注意不必要地使用括号会导致在您不希望的情况下对事物进行评估(因为括号在 VBA 中就是这样做的),因此考虑到这一点,更好的选择可能是省略
Call
关键字和括号For anyone still coming to this post, the other option is to simply omit the parentheses:
The
Call
keywords is only really in VBA for backwards compatibilty and isn't actually required.If however, you decide to use the
Call
keyword, then you have to change your syntax to suit.Both will do exactly the same thing.
That being said, there may be instances to watch out for where using parentheses unnecessarily will cause things to be evaluated where you didn't intend them to be (as parentheses do this in VBA) so with that in mind the better option is probably to omit the
Call
keyword and the parentheses