Try and catch ???
-
hi to all, i would like to know whether VBA is able to perform try and catch, if there is. how am i suppose to code it thanks veon
-
hi to all, i would like to know whether VBA is able to perform try and catch, if there is. how am i suppose to code it thanks veon
there is no try catch like .NET but u can use OnError goto let's see with an example
Private Sub Command1_Click()
On Error GoTo ErrorHandler
Error 424 'This error is displayed when there is a missing object
Exit Sub
ErrorHandler:
MsgBox "Error Number: " & Err.Number & " With The Description ->> " & Err.Description & " <<- Occured."
End Subthis is how you can handle exceptions, errors in VB6 hope it helps... :)
If the message is useful for U then please Rate This message... Be a good listener...Because Opprtunity knoughts softly...N-Joy
-
there is no try catch like .NET but u can use OnError goto let's see with an example
Private Sub Command1_Click()
On Error GoTo ErrorHandler
Error 424 'This error is displayed when there is a missing object
Exit Sub
ErrorHandler:
MsgBox "Error Number: " & Err.Number & " With The Description ->> " & Err.Description & " <<- Occured."
End Subthis is how you can handle exceptions, errors in VB6 hope it helps... :)
If the message is useful for U then please Rate This message... Be a good listener...Because Opprtunity knoughts softly...N-Joy
hi thanks for your help but now i have a problem, i paste the your code into my code , when there is no error the error msgbox will prompt the user. this is how i code it
Private Sub CommandButton3_Click()
On Error GoTo ErrorHandler
Error 424 'This error is displayed when there is a missing object
Exit Sub
Dim Wk As Worksheet
Set Wk = Sheets.Add
ss = tbx_name.Text
Application.DisplayAlerts = False
Wk.Name = ss
ErrorHandler: MsgBox "Error Number: " & Err.Number & " With The Description ->> " & Err.Description & " <<- Occured."
End Subso whats wrong with it thanks thanks veon
-
hi thanks for your help but now i have a problem, i paste the your code into my code , when there is no error the error msgbox will prompt the user. this is how i code it
Private Sub CommandButton3_Click()
On Error GoTo ErrorHandler
Error 424 'This error is displayed when there is a missing object
Exit Sub
Dim Wk As Worksheet
Set Wk = Sheets.Add
ss = tbx_name.Text
Application.DisplayAlerts = False
Wk.Name = ss
ErrorHandler: MsgBox "Error Number: " & Err.Number & " With The Description ->> " & Err.Description & " <<- Occured."
End Subso whats wrong with it thanks thanks veon
Try following code
Private Sub CommandButton3_Click()
On Error GoTo ErrorHandlerError
Dim Wk As Worksheet
Set Wk = Sheets.Add
ss = tbx_name.Text
Application.DisplayAlerts = False
Wk.Name = ss
ErrorHandler:
MsgBox "Error Number: " & Err.Number & " With The Description ->> " & Err.Description & " <<- Occured."
End Subhope it helps.... :)
If the message is useful for U then please Rate This message... Be a good listener...Because Opprtunity knoughts softly...N-Joy