Handling Macro Errors in UiPath

I want to run a marco using invoke macro inside excel application scope.
But if any error occur while the macro code is running, how can i catch it inside uipath?
I don’t want the VBA error screen to open

Did you try putting it in try catch block and check the exception message if it shows the exception from the macro ?

1 Like

If there is error while macro is running, it will be shown in the VBA Error popup. not in Uipath

Try to handle any error in macro and not throw it out on message box , instead use the Macro output property and get the error message


check this

You can use Function in Macro like for example,

Function xyz(Variable1 as string, variable2 as Integer) as string
On Error Goto EQ
Your Code Here

if Err.description.length>0 then
xyz = “FAIL” & Err.Description
End IF

end Function

Now in Execute macro make use of the Output.


I’m ressurecting this old thread as I had the same issue as OP.

My invoked vba code sometimes makes the Excel VBA error handler appear, and when this happens, the UiPath process never returns to itself, and so it the InvokeVBA activity will stay running “forever”.

As there seems to be no way to fix this from the Excel application scope, or the Invoke VBA activity, I thought to enable Error handling from within the VBA Code
It should be able to handle the 3 types of errors:

  1. Runtime Errors
  2. Syntax Errors & Compile Errors

RunTime Errors can be fixed by the On Error GoTo, like @Vijay_Tulsalkar requested, just remember to add a “Exit Function” as the last line of code before the errorhandling code begins.

But I still do not know how to handle Syntax or Compile Errors… (Write an If without a Then somewhere to test for this.)