在Excel VBA中编写代码时分解消息是可读的

我有这个function,从另一篇文章写,除了我遇到了一个问题,我的消息需要罗嗦,所以最终用户不会惊慌,说,如何打破以下的句子,所以它将是可读的我在编码?

我希望这是有道理的…谢谢。

Function GetErrMsg(ErNo As Long) As String Select Case ErNo Case 91 GetErrMsg = "This is a long message that needs to be broken into sections so it can be read normally in the programming box" End Select End Function 

你可以使用Underscore _来分解这样的代码行:

 Function GetErrMsg(ErNo As Long) As String Select Case ErNo Case 91 GetErrMsg = "This is a long message that needs to be broken into " & _ "sections so it can be read normally in the programming box" End Select End Function 

注意

当分解string时,你需要用"

然后在下划线_之前添加符号&来连接,如上例所示。

这告诉VBA该string已经结束,但是会被连接到下一行的string。