Force timeout an Execute macro activity

Hello!

I am working on this project which calls a macro to process files. My concern is that there are instances wherein the macro fails to execute properly, like it opens a dialogue box saying that there’s a runtime error, but when I try to rerun, the process will proceed smoothly.

Is there any way I can enforce a timeout for macro execution? Like if 30 mins have passed and the macro hasn’t finished, then I’ll kill the excel process then throw an exception.

I tried using the parallel activity but the robot still waits for the macro to finish before it proceeds or go back to other branch.

Can somebody help me with this please?

Thanks a lot!

@_pjflo

In parallel did you add the condition as well?

If condition is not added then it will wait

Also…you can include a try catch in your macro so that any error occuring on macro can be caught and it wont open a dialog box and can actually return normally and can throw the error back to UiPath as well

This is the structure.DisplayAlerts will stop all message boxes

Function RenameSheet ()
  Application.DisplayAlerts = False
  On Error GoTo eh
    ActiveSheet.Name = "Sheet1"
    Application.DisplayAlerts = True
    RenameSheet = "Success"
    Exit Function
   
  eh:
    Application.DisplayAlerts = True
    RenameSheet = Err.Description
End Function

Hope this helps

Cheers

Hi,

Can you try the following sample? This uses Parallel activity and InvoekWorkflowFile with Isolated option.

Sample20230331-2L.zip (14.2 KB)

Please turn on ContinueOnException in ribbon menu if run debug mode.

Regards,

Hi! Thank you for your response.

Yes, I set the parallel condition to TRUE.

Sorry but I am quite new to vb macro, I’m not sure where in the code I would place the On Error GoTo. Please check if I’m understanding it right,

The macro that I am calling is like this:

Sub Call_Macro()
     Call UnzipFolders
     Call ClearData
     Call AppendData
     Call SaveBook
End Sub

Then it should be like this:

Sub Call_Macro()
  Application.DisplayAlerts = False
  On Error GoTo eh
    Call UnzipFiles
    Call ClearDump
    Call AppendData
    Call SaveBook
    HasError = False
    Exit Function

   eh:
    Application.DisplayAlerts = True
    HasError = False

End Sub

Also, how could I fetch the value of HasError in UiPath?

Hi, thank you for your advice!

I tried the sample you gave, however, I was wondering how I could determine if excel was indeed stuck. Is it safe to assume that once the flow passes the Kill Process, then it’s stuck?

image

image

Hi,

We can judge it to be stuck when it much exceeds the time it would normally finish, I think. So it’s necessary to set delay time proper duration.

Regards,

1 Like

@_pjflo

Please check this this is how you can write…and this is a function so it would give a return value to UiPath…when successful it gives success…when failed you get the error message in the output

Function Call_Macro()
  Application.DisplayAlerts = False
  On Error GoTo eh
    Call UnzipFiles
    Call ClearDump
    Call AppendData
    Call SaveBook
    Application.DisplayAlerts = True
    Call_Macro = "Success"
    Exit Function

   eh:
    Application.DisplayAlerts = True
    Call_Macro = Err.Description

End Function

Hope this helps

Cheers

1 Like

Thank you, @Anil_G and @Yoichi ! I really appreciate your help. I’ve tried to implement your suggestions and both worked! Such great approach and ideas that I would definitely use from here onwards.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.