Hi,
I use a Try-Catch block to catch errors in my code.
This is not strictly VBA code, but VB.NET code which is very similar.
I am not sure this is the appropriate forum.
I use a general exception to trap my error:
When the error I have in mind happens, I always get this error message:
The error happens when a range is not selected when it is required to be selected.
Here is the code:
I wish to use a more specific Exception to catch this type of error for 2 reasons:
(a) I can display a more specific and helpful message
(b) I can keep the general Exception to trap all other exceptions
Can anybody tell me which exception can be used?
I tried:
Thanks
Leon
I use a Try-Catch block to catch errors in my code.
This is not strictly VBA code, but VB.NET code which is very similar.
I am not sure this is the appropriate forum.
I use a general exception to trap my error:
Code:
Try
Catch ex As Exception
End Try
When the error I have in mind happens, I always get this error message:
Object reference not set to an instance of an object
The error happens when a range is not selected when it is required to be selected.
Here is the code:
Code:
For Each CmtCell In SelectedRange
If Not CmtCell.Comment Is Nothing Then CountCmts = CountCmts + 1
Next
I wish to use a more specific Exception to catch this type of error for 2 reasons:
(a) I can display a more specific and helpful message
(b) I can keep the general Exception to trap all other exceptions
Can anybody tell me which exception can be used?
I tried:
Code:
Catch ex As NullReferenceException '// this works & gives the same message
Code:
Catch ex As ObjectDisposedException '// this does not work
Thanks
Leon