Check if file is password protected

absarshah

New Member
Joined
May 16, 2019
Messages
3
Hi everyone! I'm looking for a way to check if an Excel file is password protected. If so, VBA should open it with the "default" office password. This should happen anytime a file is opened by any means (i.e. from Windows Explorer, and not just through another piece of code in another Excel)

I tried using CExcelEvents to monitor when a file is opened, and then execute a specific code when a file is opened. Unfortunately, this event is only triggered once the password has already been entered and the file is open. I would like to trigger code BEFORE the file is actually opened, so that I could then use the Workbook.Open method to open the file with a specific password.

Any help appreciated!
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Why can't the user insert the password manually to open the protected excel file(s)?

The only workaround I can think of is to have an excel file in a hidden excel instance which is loaded whenever the computer is switched on .

This hidden excel file will have code to monitor when a password protected excel file is being opened either via code or from the UI.

The code in the hidden file will set up a system wide shell hook that will detect the password prompt dialogbox when it comes up and will automatically send to it the required password as click the ok button.

Not easy but I think should work .
 
Last edited:
Upvote 0
Why can't the user insert the password manually to open the protected excel file(s)?

The only workaround I can think of is to have an excel file in a hidden excel instance which is loaded whenever the computer is switched on .

This hidden excel file will have code to monitor when a password protected excel file is being opened either via code or from the UI.

It's an efficiency matter. Due to confidentiality reasons, any file which leaves the company server (e.g. over email) must be encrypted with a password. Which means that basically all of our documentation is encrypted. This of course gets very tiresome :)
 
Upvote 0
@absarshah

Which version\Edition of excel do you use ?

Edit:

And are the files just password protected but have full write access to them ?

And is the password the same for all files ?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,887
Messages
6,175,199
Members
452,617
Latest member
Narendra Babu D

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top