Stuck with some weird error in VBA

692 views Asked by At

I am doing project in powerpoint 2007 automation. In that i am using macro programming (VBA). I am getting the following error while run the macro.

Err.Number= -2147024809 (80070057)

but my concern is not with error Because i want to catch this error and base on this error i want to perform some action.

Thats why i try to code like this for error handing code:

OnError Goto Err:
'some code

Err:
If Err.number = -2147024809 (80070057) then
'do something
end if
Resume next

So bascially if i write error number in this way then its not allow it. it gives error.

and major thing is when error occurs sometime it did not go to "Err : ". It just pop-up error with "End" and "Debug" options.

3

There are 3 answers

0
Steve Rindsberg On BEST ANSWER

While it seems to work, I'd be cautious about using a reserved object name (Err) as a label, for one thing.

On Error GoTo ErrorHandler

' Your code here

' Make sure you don't hit the errorhandler when there's
' no error:
NormalExit:
Exit Sub ' or Function, whichever this is

ErrorHandler:
If err.Number = 123456788 Then
    ' Take corrective action
    ' then continue
    Resume Next
End If
' Trap other specific or general errors here

' Then make sure you know where you're going to exit:
Resume NormalExit

If you need to trap very specific errors that might occur only at certain places in your code, you can also do a local errorhandler:

On Error Resume Next

' Some code that might cause problems

' Did it throw the error you're trying to trap?
If Err.Number = 12398745 then 
  ' Corrective action
End If

' And now we return to our regularly scheduled error trapping
On Error GoTo ErrorHandler
2
Alex K. On

Error numbers are numeric: -2147024809, its just displayed to you as the string "-2147024809 (80070057)" for clarity (80070057) being the error number in hexadecimal.

You want;

if err.number = -2147024809 then ....

or if you so choose

if err.number = &h80070057 then ....
0
slugster On

The 80070057 part of the error message is the unsigned hexadecimal version of the negative number -2147024809. Remove that part of your code and you will be fine, if you want to keep track of the hex version of the number (can be useful for researching errors via Google etc) then just add it as a comment.