尝试在 Excel VBA 中将子语句拆分为多行

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

Trying to split a sub statement over multiple lines in Excel VBA

vba

提问by user3918381

I am trying to write a sub statement which is receiving multiple arguments from the other sub which calls it (apologies, I am quite new at this - so my terminology may not be spot on).

我正在尝试编写一个 sub 语句,该语句从另一个调用它的 sub 接收多个参数(抱歉,我对此很陌生 - 所以我的术语可能不正确)。

The number of arguments I am passing is quite a few, so it extends off my screen. For ease of reading I would like to split the argument list over multiple lines. I have tried to use the "Space underscore" trick like you would within the sub. However, when I do, VBA stops recognising the subas it's own routine.

我传递的参数数量很多,所以它超出了我的屏幕。为了便于阅读,我想将参数列表分成多行。我试图像在sub. 但是,当我这样做时,VBA 不再将sub其识别为它自己的例程。

Any ideas how I can do this?

任何想法我怎么能做到这一点?

E.g.This works:

例如这有效:

... 
End Sub ' from previous subroutine

Sub openfile(ByVal Res, ByVal Book, ByVal inp) 'there are other arguments as well, but I have shortened them for convenience here. 

....

End Sub

But this doesn't:

但这不会:

... 
End sub ' from previous subroutine

Sub openfile(ByVal Res, ByVal Book, _

ByVal inp) 'there are other arguments as well, but I have shortened them for convenience here. 

....

End Sub

回答by djikay

You can't have a completelyempty line (a blank line) between the _and the next part of your code. Remove the extra line and you'll be fine. Basically, do this:

在代码的下一部分和下一部分之间不能有完全空的行(空行)_。去掉多余的线,你会没事的。基本上,这样做:

Sub openfile(ByVal Res, ByVal Book, _
ByVal inp) 'there are other arguments as well, but I have shortened them for convenience here.

If you really want to have an almostblank line, you can do this:

如果你真的想要一个几乎空白的行,你可以这样做:

Sub openfile(ByVal Res, ByVal Book, _
 _
ByVal inp) 'there are other arguments as well, but I have shortened them for convenience here.

Notice that the _that's on its own line must have a space character in front of it; that's important.

请注意,_在它自己的行前面必须有一个空格字符;这很重要。