我似乎无法找到具体的内容。 我知道为了在多行上分割一段代码,你只需添加" _" 到该行的末尾。
但是,我注意到我的一些代码只在我使用"& _" ,以下一行包含一组额外的语音标记,如果它在一行上就不包括在内,为什么会这样?
一行代码:
Msg1 = MsgBox("Removing an LPA will remove ALL of their details from the database, including their documents - You cannot undo this action. Do you wish to continue?", vbYesNo, "WARNING!")
分开的代码行有效:
Msg1 = MsgBox("Removing an LPA will remove ALL of their details from the database," & _
"including their documents - You cannot undo this action. Do you wish to" & _
" continue?", vbYesNo, "WARNING!")
分开的代码行不起作用:
Msg1 = MsgBox("Removing an LPA will remove ALL of their details from the database, _
including their documents - You cannot undo this action. Do you wish to _
continue?", vbYesNo, "WARNING!")
那么"& _" 和" _"吗
如果不关闭并打开一组新的语音标记,你能否在新行上继续使用字符串?
答案 0 :(得分:5)
VBA(以及VB6,VBScript和早期版本的VB.NET)不支持多行字符串文字:
' Doesn't work
myString = "a
b c"
' Doesn't work either, because _ does not have a special meaning when
' inside double quotes.
myString = "a _
b c"
因此,您需要将字符串拆分为多个字符串。您可以使用&
运算符将它们连接起来:
myString = "a " & "b c" ' yields "a b c"
然后然后你可以在两个令牌之间的任何地方将你的字符串分开:
myString = "a " & _
"b c" ' my personal preference
' or
myString = "a " _
& "b c"
' or
myString = "a " _
& _
"b c"
' or even
myString _
= _
"a " _
& _
"b c"
答案 1 :(得分:1)
&安培; =连接两个字符串,_ =行分隔符
与c#或Java不同,VBA代码行不以制造商(;)结尾,而是VBA IDE将每一行用作一个代码行。这会强迫你通过&和每一行连接字符串。登录。
还要注意最大线路延续高于此数字25,您将收到错误(线路延续太多)
https://msdn.microsoft.com/en-us/library/office/gg264236.aspx