unprotect VBA project with code

Z

zSplash

How do I programmatically unprotect a VBA project? That is, I have copied
my Normal.dot as an addin, and now want to programmatically re-name the
addin (so that I can use VBE.VBProjects(x).Name to modify the code). I
tried:

Documents.Open FileName:="C:\newAddin.dot"
VBE.ActiveVBProject.Unprotect "password"

and get the error 438, Object doesn't support this property or method. Not
to complain, but it seems like I'm going in circles trying to do something
relatively simple. Please help.

TIA
 
J

Jezebel

I don't know that anyone has found a way to do this. Even using oddball
techniques like SendKeys or making API calls to seed the Windows message
queue.

But are you sure that's the problem? You get the 'Project is unviewable'
message on add-ins if the add-in is not actually open (that is you need to
switch to Word's main window and open the add-in file itself). Otherwise the
add-in is loaded and you can execute its code, but you can't view it or
manipulate the code.
 
G

Gene

Try this:

In The Visual Basic Editor select Tools . . . References
Check Microsoft Visual Basic for Applications Extensibility 5.3 (number may
be different depending on your version - I am using office XP)
Click OK
Close the VBE and restart MS Word.

Try your code again.

Hope this helps,

Gene
 
Z

zSplash

Thanks for your help, Jezebel and Gene. I should not have said "as an
addin" but "as a template.

The error I get is "Run-time error 50289: Can't perform operation once the
project is protected." What I'm trying to do is 2 things: rename the
locked project and use VBE to edit two lines of code in the locked project.

The project needs to be locked. I guess I'll have to just manually unlock
and rename the project before running the code, and then, after running the
code, go back and lock the project again. Rats.

st.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top