在 VBA 中调用 Sub [英] Calling a Sub in VBA

查看:61
本文介绍了在 VBA 中调用 Sub的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的简化脚本:

    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不接电话?

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?

推荐答案

尝试 -

Call CatSubProduktAreakum(Stattyp, Daty + UBound(SubCategories) + 2)

至于原因,这来自 MSDN 通过这个问题 - WhatCall 关键字在 VB6 中有什么作用?

As for the reason, this from MSDN via this question - What does the Call keyword do in VB6?

在调用过程时不需要使用 Call 关键字.但是,如果您使用 Call 关键字来调用需要参数,参数列表必须括在括号中.如果省略Call 关键字,您还必须省略括号参数列表.如果您使用 Call 语法来调用任何内在或用户自定义函数,函数的返回值被丢弃.

You are not required to use the Call keyword when calling a procedure. However, if you use the Call keyword to call a procedure that requires arguments, argumentlist must be enclosed in parentheses. If you omit the Call keyword, you also must omit the parentheses around argumentlist. If you use either Call syntax to call any intrinsic or user-defined function, the function's return value is discarded.

这篇关于在 VBA 中调用 Sub的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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