views:

11957

answers:

5

How can I programmatically remove a (known) password from an Excel VBA project?

To be clear; I want to remove the password from the VBA Project, not the workbook or any worksheets.

+1  A: 

In VBA use

ActiveWorkbook.Unprotect (Password)

EDIT: There is an ActiveWorkbook.VBProject.Protection property, but it is ReadOnly. So I guess the answer is: You can't. Sorry.

Treb
+2  A: 

I found this here that describes how to set the VBA Project Password. You should be able to modify it to unset the VBA Project Password.

This one does not use SendKeys.

Let me know if this helps! JFV

JFV
+4  A: 

This has a simple method using SendKeys to unprotect the VBA project. This would get you into the project, so you'd have to continue on using SendKeys to figure out a way to remove the password protection: http://www.pcreview.co.uk/forums/thread-989191.php

And here's one that uses a more advanced, somewhat more reliable method for unprotecting. Again, it will only unlock the VB project for you. http://www.ozgrid.com/forum/showthread.php?t=13006&page=2

I haven't tried either method, but this may save you some time if it's what you need to do...

Jon Fournier
A: 

Did some googling - it seems there is no direct way - you have to use a sendkeys kludge

http://www.mrexcel.com/forum/showthread.php?t=49034

DJ
A: 

As others have said, you can't outside of using SendKeys.

However I tried using SendKeys with Excel 2002 and never got it to work.

If there are just a few projects you can open them and then select them programmatically, but you'll still have to click on each and enter the password.

JRL