Re: Programming to VBE

R

Ron de Bruin

Hi Ajit

Only with Sendkeys it is possible

Read this old post from Bill Manville

------------------------
You will need to use SendKeys to unprotect the project(s) and reprotect
after replacing the modules.

Here's something to get you started:

Sub TestProtect()
Workbooks.Add.SaveAs "C:\Temp\Book1.xls"
ProtectVBProject Workbooks("Book1.xls"), "Jack"
Workbooks("Book1.xls").Close True
End Sub

Sub TestUnprotect()
Workbooks.Open "C:\Temp\Book1.xls"
UnprotectVBProject Workbooks("Book1.xls"), "Jack"
End Sub


Sub UnprotectVBProject(WB As Workbook, ByVal Password As String)
Dim vbProj As Object

Set vbProj = WB.VBProject

'can't do it if already unlocked!
If vbProj.Protection <> 1 Then Exit Sub

Set Application.VBE.ActiveVBProject = vbProj

' now use lovely SendKeys to quote the project password
SendKeys Password & "~~"
Application.VBE.CommandBars(1).FindControl(Id:=2578,
recursive:=True).Execute
End Sub

Sub ProtectVBProject(WB As Workbook, ByVal Password As String)
Dim vbProj As Object

Set vbProj = WB.VBProject

'can't do it if already locked!
If vbProj.Protection = 1 Then Exit Sub

Set Application.VBE.ActiveVBProject = vbProj

' now use lovely SendKeys to set the project password
SendKeys "+{TAB}{RIGHT}%V{+}{TAB}" & Password & "{TAB}" & _
Password & "~"

Application.VBE.CommandBars(1).FindControl(Id:=2578,
recursive:=True).Execute

WB.Save
End Sub
 
H

Hari

Hi Ajit,

Dunno an iota about send keys etc. But..
Is the password for all the files in your VB project ABC?

Regards,
Hari
India
 

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