vba 我的 Excel 2007 宏 - Argument not optional 是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7089222/
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-08 11:47:11  来源:igfitidea点击:

My Excel 2007 macro - what does Argument not optional mean?

excelvba

提问by Nathaniel_613

what is wrong with my macro?

我的宏有什么问题?

Please advise me what is wrong with my Excel 2007 macro thank you very much

请告诉我我的 Excel 2007 宏有什么问题,非常感谢

采纳答案by aevanko

If a parameter is supposed to be sent to a function by its definition but it is not sent, this error occurs. Please note that you canassign optional paramters like this:

如果一个参数应该根据其定义发送给函数,但没有发送,则会发生此错误。请注意,您可以像这样分配可选参数:

Function Something(ByVal text as String, Optional number as Long = 26)

By placing the Optionalkeyword, the function can still be called even without that paramater being passed in to it. The = xxx is where you put the default value in the case that it is not provided.

通过放置Optional关键字,即使没有将该参数传递给函数,仍然可以调用该函数。= xxx 是您在未提供默认值的情况下放置默认值的地方。

If you decide not to declare the type of the Optional paramter (making it a Variant), you can use the ultra convenient IsMissing()function to see if it was passed in or not.

如果您决定不声明 Optional 参数的类型(使其成为 Variant),您可以使用非常方便的IsMissing()函数来查看它是否被传入。

回答by Nodebody

The function needs one or more parameters (argument) which you didn't provide. And since that argument is not optional, meaning you haveto provide it, Excel can't execute your macro.

该函数需要一个或多个您未提供的参数(参数)。由于该参数不是可选的,这意味着您必须提供它,因此 Excel 无法执行您的宏。

回答by djna

You are not passing a number into the second call to inchesToPoints()

您没有将数字传递给对inchesToPoints() 的第二次调用

回答by Sangram Nandkhile

Seems like function .InchesToPoints()needs argument to be passed. Like you have passed value 0.36 in your first call of .InchesToPoints()for variable .LeftMargin

似乎函数.InchesToPoints()需要传递参数。就像您在第一次调用.InchesToPoints()for 变量时传递了值 0.36.LeftMargin

Pass the proper argument for function called for variable .RightMargin

为变量调用的函数传递正确的参数 .RightMargin