Is there a way to Check if a macro encountered an error during my "Invoke VBA" activity?

Hi, I was wondering if there was a way to check for macro errors after an Invoke VBA activity is launched and fault the process if there was an error in the macro. I have a process that sat overnight because the macro encountered an error.

Hi @Ashley_Bell

I think if you enabled the error handling in macro and return a result, it should help.

returning status/error from macro back to invoke vba should help with that.

please give it a try.

2 Likes

@Ashley_Bell,

Use try catch in your code and in case of error assign error message to a output argument.

Remember the activity can only return string datatype.

1 Like

@Ashley_Bell

you can use on error goto and create a function and return the error messsage gracefully

sample template

function myfunc()

on error goto ErrorLabel

yourcode here
myfunc="success"
Exit Function

ErrorLabel:
myfunc = err.description


End function

cheers

1 Like

@Ashley_Bell

You can give a try from your macro

if any issue occurs from your macro store some keyword or error message and that should come as output of invoke activity,
after running that activity you can check the output for that error message, if it find you can throw exception or else you can continue with your process.

Happy Automation

Use below
Function VBAFUNCTIONNAME
On Error GoTo ErrorHandler



Your Code


ErrorHandler:
VBAFUNCTIONNAME = Err.Description

End Function

your vba code should like this, and in UiPath activity when you use , invoke vba or run spreadsheet macro, in output add your variable,if var is empty then macro ran correctly , else you will get error description in that variable.Also you can customize your vba code so your var will hold some value which you can explicitly ideantify success run and error.