How to detect if an Excel file is password-protected

My customer gets Excel files from the business, some of them are password-protected even if they shouldn’t. In that case, the goal is to detect this and generates an error report, otherwise the robot is blocked.
Consequently I would like to detect if an Excel file is password-protected before trying to read it. I found this post: Check whether excel is password protected?
But it does not work because the robot is blocked as soon as the “Use Excel File” activity executes. In fact, I have a “Excel Process Scope” activity that includes a “Use Excel file” activity with my sheet file name. When the “Use Excel file” activity executes, Excel starts, opens the file and waits for the password, and the robot does not go further.

Thanks for any help.

What about a workbook read range (just for the sake of checking the file) inside a try catch?
Inside the exception area use something like:
If - exception.ToString.Contains(“password”) - assign / write File is encrypted, or just set boolean var as true like password = True

1 Like

I finally did something similar, I inserted the Use Excel file activity in a try/catch and I set a dummy password. If the Excel is password-protected, the password is wrong and it generates an exception, and if the Excel has no password, it works as well.
Your solution is better though because you get an explicit error message that ensures it fails because of the password.

Thanks for your help !!

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