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.
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.
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
Err.Clear
End If
Continue with the script
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
ErrorHandler:
MsgBox "An error occurred: " & Err.Description
End Sub