Jump to content

Identify the excel file that may need a password


Recommended Posts

Dear members of the forum,

I need to open excel files that may or may not need a password and finally move the files that needs password to manual queue.

Is there a fastest way to do this?

 

PS: I have a huge respect for the rules of this forum. I am not asking assistance to override any security measure. I just need to segregate the files that needs passwords.

Link to comment
Share on other sites

  • Moderators

Last I knew there was no way to know if a workbook was password protected without opening it (someone may prove me wrong). About the best you could do was loop through your list of files and try to open them (look at _Excel_BookOpen) by specifying the password parameter (a simple "abc" will suffice). If the workbook has no password on it, it will open with a code 0; if it does have a password it will throw an @error of 3 and @extended of -2147352567. You can then move the file.

Pseudo:

#include <Excel.au3>

Local $oExcel = _Excel_Open()
Local $oWorkbook = _Excel_BookOpen($oExcel, @DesktopDir & "\test.xlsx", True, True, "abc", "abc")
    If @error Then
        if @extended = "-2147352567" Then
            ;Move file
        Else
            ;Handle other @error such as missing file
        EndIf
    Else
        ;File not password protected, do whatever
    EndIf

_Excel_BookClose($oWorkbook)
_Excel_Close($oExcel)

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

@JLogan3o13,

great solution :thumbsup:
I've added it to the Excel section in the wiki.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...