Com Interop Errorcode

R

Raja

Hi,

where can I find the meaning of the error code that retun from the com interop

Regards,
Raja
 
G

Gary Brown

In your procedure's error handling, put something like...

Debug.Print err.number & " - " & Err.Description

or

Msgbox err.number & " - " & Err.Description
 
R

Raja

Yes, I know that. I mean what the number means? where I can find a list
of all numbers?

For exmaple, the Workbook.Open method could throw exception when you try to
open a workbook that already opened. Excel display to use a message say "Do
you want to update.....". and if the user click No, Open method throw
exception with number. and I interested to see all possible error that the
open method could throw?

Regards,
Raja
 
G

Gary Brown

I don't know about a list of ONLY errors produced when opening a workbook but
the following procedure [ErrorList] will list all error messages that VBA
Excel throws. If a number is not listed, the Description is
'Application-defined or object-defined error'.

'/==============================================/
Public Sub ErrorList()
'create list of all errors with descriptions from
' Active Cell down
Dim i As Long, iMax As Long, x As Long
Dim varAnswer As Variant

On Error GoTo err_Sub

iMax = 5000

varAnswer = _
MsgBox("The process will list errors and descriptions." _
& vbCr & vbCr & "Any errors with the description " _
& vbCr & "'Application-defined or " & _
"object-defined error' will not be included in the list." _
& vbCr & vbCr & _
"All cells below the Active cell will be erased." & _
vbCr & vbCr & "Continue?", _
vbCritical + vbYesNo + vbDefaultButton2, _
"Create Error Listing...")

If varAnswer = vbYes Then
On Error Resume Next
ActiveCell.Offset(x, 0).value = "Err.Number"
ActiveCell.Offset(x, 1).value = "Err.Description"

For i = 1 To iMax
Err.Clear
Err.Raise i
If Len(Err.Description) <> 0 And _
Err.Description <> _
"Application-defined or object-defined error" Then
x = x + 1
ActiveCell.Offset(x, 0).value = Err.Number
ActiveCell.Offset(x, 1).value = Err.Description
End If
Err.Clear
Next i
End If

On Error GoTo err_Sub
Err.Clear

Cells.EntireColumn.AutoFit
ActiveCell.Offset(1, 0).Activate
ActiveWindow.FreezePanes = False
ActiveWindow.FreezePanes = True
ActiveWindow.Zoom = 75

exit_Sub:
Exit Sub

err_Sub:
GoTo exit_Sub
End Sub
'/==============================================/


--
Hope this helps.
If it does, please click the Yes button.
Thanks in advance for your feedback.
Gary Brown
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top