Search code examples
vbapowerpointpowerpoint-2007

Stuck with some weird error in VBA


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.


Solution

  • 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