自动关闭 Msgbox对话框:
Private Declare Function MsgBoxEx Lib "user32" Alias "MessageBoxTimeoutA" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As VbMsgBoxStyle, ByVal wlange As Long, ByVal dwTimeout As Long) As Long
Private Sub 测试自动关闭对话框()
MsgBoxEx 0, "显示内容:2秒后自动关闭", "标题", vbYesNo + vbInformation, 1, 2000
End Su
错误捕捉:
例子一:
On Error Resume Next ‘如果遇到错误,不管错误,继续往下执行,但如果嵌套了其他错误处理语句,这些错误处理语句还是会按照自己规则运行
语句xxxx
On Error GoTo 0 ’结束错误捕捉
例子二:
Sub 例子过程()
On Error GoTo Err_Handle ‘之后语句出错则跳转至 Err_Handle 标签处
处理语句1 ‘若出错,则跳转到 Err_Handle
On Error GoTo 0 ‘跳出错误捕捉,之后语句若出错,自动弹出出错框
处理语句2 ‘若出错则弹出错误,可调试或结束
Exit Sub ‘如果没有这个退出过程语句,会一直执行下去
Err_Handle:
MsgBox ("不存在该数字")
End Sub
原文地址:https://blog.51cto.com/alun51cto/2392898
时间: 2024-10-16 17:31:08