RawrRanger
RawrRanger

Reputation: 43

PowerPoint VBA Error handling not working

I'm tried to use PowerPoint-VBA to handle some code exception/error, but I cannot trigger it successfully, even using the simplest example code from the tutorial.

The gif below shows despite I add "On Error" before 6/0 but it still shows divided by zero runtime error.

I've tried similar code on at least 3 different computer with different PowerPoint version 2013, 2016, 2019 respectively but found they all behaves the same.

I would like to know whether I missed something obvious or should I enable or turn on some sort of option in the setting?

Thanks.

The code sample that I use for the test is as below, this is just an example that I found on the net for testing.

Option Explicit
Sub UsingGotoLine()
    On Error GoTo eh
    Dim x As Long, y As Long

    x = 6
    y = 6 / 0
    x = 7

Done:
    Exit Sub

eh:
    MsgBox "The following error occurred " & Err.Description

End Sub

unable to handle error

Upvotes: 0

Views: 728

Answers (1)

Steve Rindsberg
Steve Rindsberg

Reputation: 14809

In the VBA IDE, choose Tools | Options Look at the General tab. If "Break on All Errors" is chosen, I get the same result as you. Effectively, your error handler is disabled. This can be useful to make sure your error handling isn't masking problem.

Instead, select "Break on unhandled errors" and it'll behave as you expect it to.

If not, we'll need to discuss percussive maintenance.

enter image description here

Upvotes: 1

Related Questions