MrExcel Publishing
Your One Stop for Excel Tips & Solutions


Posted by Jerid on May 18, 2001 12:00 PM

Hello All.

Does anyone have a way to unlock/lock a VBProject through code?

I'm trying to use one excel application to make copies of another excel application, then change one line of code in the copy.

My plans were to Copy the original file, open the copy, unlock the VBProject inside the copy, replace one line of code, and save.

I have it sort of working by using SENDKEY to prompt for the VBProject password dialog box, enter the password, followed by the Enter key twice. But, because I have two differnt workbooks open at the same time (two VBProjects) and I keep switching back between them, my procedure falls apart after the first file when the wrong VBProject gets the send key because I can't find a way to select a VBProject through code.

Any thoughts?

Thanks Jerid

Posted by Ivan Moala on May 19, 2001 12:37 AM

What code are you using ??
I have done similar to this...key here being to 1st
close ALL open VBA windows THEN activate the workbooks VBA.


Posted by Jerid on May 21, 2001 1:14 PM

Here is the code I'm using, only the names have changed to protect the innocent

For Each vbProj In Application.VBE.VBProjects
If vbProj.Name = "MYVBProject" Then
Application.SendKeys "%tepassword{ENTER}{ENTER}", True
sLine = Workbooks("myWorkbook").VBProject.VBComponents("myModule").CodeModule.Lines(16, 1)
sLine = Left(sLine, 38) & sConstant
Workbooks("myWorkbook").VBProject.VBComponents("myModule").CodeModule.ReplaceLine 16, sLine
End If
Next vbProj