VBA这个MsgBox语法出了什么问题

时间:2015-07-06 18:33:52

标签: vba excel-vba ms-office excel

当我尝试编译时我给出了这个错误:

  

编译错误:

     

语法错误

以下是代码:

Public Sub ErrorHandler()
'   The code is cleaned up by using ErrorHandler as a function because it has to be written out fewer times, and makes changing ErrorHandler easier

MsgBox("Error detected" & vbNewLine & vbNewLine & "Error " & Err.Number, vbCritical, "Error Handler: Error " & Err.Number)

End Sub

1 个答案:

答案 0 :(得分:0)

除非子程序返回一个值,即分配给变量不需要使用paranthesis

MsgBox "Error detected" & vbNewLine & vbNewLine & "Error " & Err.Number, vbCritical, "Error Handler: Error " & Err.Number

如果msgbox需要回复一个答案,那么以下是正确的语法

response = MsgBox ("Error detected" & vbNewLine & vbNewLine & "Error " & Err.Number & "Do you want to retry", vbYesNo, "Error Handler: Error " & Err.Number)