Set an Open Password for an Excel File using VBA

I want to set a Password to Open an Excel File using VBA.

I do not want to use the built Password option in Excel (Save As -> Tools -> Password to Open).

I want to use a Macro that prompts the user for a Password before they can do anything within the file.

Is this possible?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Saurabh Singh TeotiaCommented:
I won't recommend using this way due the fact what if the user doesn't enables the macro then as a result he will be able to navigate to the file easily..

Any particular reason why you don't want to use inbuilt feature??

thomas-sherrouseAuthor Commented:
I wanted to see if I could reference the file with out the inbuilt password. Anyone who would be utilizing the referenced sheet wouldn't be sophisticated enough to find out any other information.

I thought there was a way to locked down the sheet and force someone to enable macros or a way to block access to through VBA, but if there isn't I can figure something else out.
Martin LissOlder than dirtCommented:
I interpret your question as saying that you don't want to use Excel's built-in workbook password. If all you want to do is to prevent the unsophisticated user from seeing or modifying your macros then from Excel go to the Visual Basic IDE by clicking Alt+F11. From there choose the Tools>VBAProject Properties menu item and click the 'Protection' tab. On that tab, check 'Lock project from viewing' enter and confirm a password and click 'OK'. Finally close and reopen the workbook. I've attached a demo workbook where I've done that and the password is "password".

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Martin LissOlder than dirtCommented:
If my post above isn't want you want then perhaps you just want to protect a sheet. To do so go to the 'Review' tab and select 'Protect Sheet' from the 'Changes' group and enter and confirm your password when prompted.
Martin LissOlder than dirtCommented:
@thomas-sherrouse: I just noticed that you gave me a "B" grade. Why? Please see this EE article on grading particularly where it says the following. The bolding is mine.
B is the grade given for acceptable solutions, or a link to an acceptable solution. A B grade means the solution given lacked some information or required you to do a good amount of extra work to resolve the problem. When closing the question, the asker should explain why a B grade was awarded

Please consider Requesting Attention so that a moderator can help you change the grade.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.