vba 调用子例程“预期的变量或过程,而不是模块”时出错。

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14114969/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 19:02:19  来源:igfitidea点击:

Error when calling subroutines "Expected Variable or Procedure, not Module."

excelvba

提问by uncertaintea

I am trying to create a subroutine that will call one of a couple of other subroutines.

我正在尝试创建一个将调用其他几个子例程之一的子例程。

When I use a call inside an if statement I get an error:

当我在 if 语句中使用调用时,出现错误:

Expected Variable or Procedure, not Module.

预期的变量或过程,而不是模块。

Here's the call procedure:

下面是调用过程:

Call schedule_3_day(shift1, ActiveWorkbook.Sheets("Employees"), ActiveWorkbook.Sheets("3 Day Template"))

Here's the function to which it refers.

这是它所指的函数。

Sub schedule_3_day(ByRef sourcesheet As Worksheet, ByRef employeesheet As Worksheet, ByRef template As Worksheet)

On it's own, i.e. when it is a self contained subroutine, schedule_3_day works as intended. I am trying to alter it to pass user defined variables into it.

就其本身而言,即当它是一个自包含的子程序时,schedule_3_day 按预期工作。我试图改变它以将用户定义的变量传递给它。

回答by Tony Dallimore

Background

背景

When Excel creates modules it names then Module1, Module2and so on. This can get confusing if, like me, you divide your routines into sets: Global, Task1, Task2 and so on.

当 Excel 创建模块时,它会命名为Module1Module2等等。如果像我一样将例程划分为多个集合,这可能会令人困惑:全局、任务 1、任务 2 等等。

Not everyone seems to know you can rename Excel modules. This is made obvious in Access where you are asked for a module's name. For Excel you have to discover this facility for yourself.

似乎不是每个人都知道您可以重命名 Excel 模块。这在要求您输入模块名称的 Access 中很明显。对于 Excel,您必须亲自发现此功能。

Select the module, click F4 and the modules properties will appear in a floating window just as it does for a form. The only property is Namewhich you can change to anything that conforms to the rules for a variable name. Using this facility I rename my modules: Global, Task1, Task2and so on, which allows me to easily identify the module I want to work on today.

选择模块,单击 F4,模块属性将出现在浮动窗口中,就像它在表单中一样。唯一的属性是Name您可以更改为符合变量名称规则的任何内容。使用此工具重新命名我的模块:GlobalTask1Task2等等,这让我很容易地确定我想今天的工作模块。

Limitation

局限性

I believe you have encountered the one limitation with the choice of name for a module.

我相信您遇到了选择模块名称的一个限制。

If I rename a module Task1then a sub, function, or global variable within that module named Task1is invisible from outside.

如果我重命名一个模块,Task1那么该模块中的子、函数或全局变量Task1从外部是不可见的。

The error message "Expected Variable or Procedure, Not Module" is to be expected if the module containing sub schedule_3_day(ByRef ...is named schedule3_day.

如果包含的模块sub schedule_3_day(ByRef ...名为 ,则会出现错误消息“预期变量或过程,而非模块” schedule3_day