有没有办法说如果错误1004出现,显示消息" message“,如果出现错误9,则显示消息"Message2”,而不是为最终用户显示通用的非描述符极客发言消息?
发布于 2012-07-16 22:25:30
你要做的就是所谓的错误处理。
请参阅此示例。您可以使用Err.Number捕获错误号
Sub Sample()
On Error GoTo Whoa
'~~> Rest of the code
Exit Sub
Whoa:
Select Case Err.Number
Case 9
MsgBox "Message1"
Case 1004
MsgBox "Message2"
End Select
End Sub后续
Sub Sample1()
On Error GoTo Whoa
'~~> Rest of the code
Exit Sub
Whoa:
MsgBox GetErrMsg(Err.Number)
End Sub
Sub Sample2()
On Error GoTo Whoa
'~~> Rest of the code
Exit Sub
Whoa:
MsgBox GetErrMsg(Err.Number)
End Sub
Function GetErrMsg(ErNo As Long) As String
Select Case ErNo
Case 9
GetErrMsg = "Message1"
Case 1004
GetErrMsg = "Message2"
Case Else
GetErrMsg = "Message3"
End Select
End Functionhttps://stackoverflow.com/questions/11506364
复制相似问题