How to handle exception in Invoke VBA Excel Activity

Hi Community folks,

I am using the Macro with VB code to automate the excel process by using Invoke VBA Excel activity.
If any error occurred in the VB code, the bot stuck at Invoke VBA activity and displayed popup.

Is there any solution to handle the exception, If the exception occur in VB Code it will throw back to UiPath. Let me know is there any chance to modify in VB Code or other approach.

Note : I encapsulated the whole process in UiPath with Try Catch.

Check the below image while getting popup but the bot didn’t stop until click on the End button in popup.

Any Suggestions @Anil_G @Yoichi @ppr @Palaniyappan @postwick @Gokul001 @supermanPunch

Thanks in advance!!



Basically it’s bettter to handle exception in VBA and return code to UiPath, I think.
If it’s difficult to modeify VBA code, parallel activity and Click activity for pressing the button might help you.


1 Like


Please use try catch in macro


1 Like

Hi @lrtetala

Have a look on the sample code for exception handling

On Error Resume Next

' Code that may cause an error
'Check for errors
If Err.Number <> 0 Then
    WScript.Echo "Error Number: " & Err.Number
    WScript.Echo "Error Description: " & Err.Description
    ' Clear the error so that it doesn't affect the rest of the script
End If
Continue with the script


1 Like

This is quite common
I would recommend to handle it within VBA itself so that ur can throw the exception to UiPath activities to proceed further

Within your VBA code, you can add error-handling routines using On Error GoTo <Label> and On Error Resume Next statements. When an error occurs, you can log it or even pop up a message within VBA itself. This way, the VBA code doesn’t get stuck, and you can handle errors gracefully.Example in VBA:

Sub YourMacro() 

      On Error GoTo ErrorHandler 
       ' Your VBA code here 
Exit Sub 

       MsgBox "An error occurred: " & Err.Description 

End Sub

Hope this helps

Cheers @lrtetala

1 Like

this is good but how return the error msg to UiPath