Check if an Excel File is Password Protected or Not

Hi,
I have a use case where one of the excel files for each record is password protected. Bot has to figure out which excel file is password protected.

Currently I am using Excel application scope with the path of the locked file and inside it I call the macro.

Function Main() as Boolean

Main = ActiveWorkbook.HasPassword

End Function

This works if the file is not-locked. If the file is locked excel application scope is throwing an error.

I want to know if there is a better way of knowing if excel file is password protected or not?

I used try catch around excel application scope and catched the exception if item is locked. It is working as of now.

Hi,

I used try catch around excel application scope and catched the exception if item is locked.

I think it’s no problem as practical approach, because basically we cannot know if the file is protected by password before it’s opened.

Regards,

1 Like

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