C
Crookie74
I need to be able to unlock the VBA Project within my code. I have
used the following code that I found on the net
Private Sub UnprotectVBProject(WB As Workbook, ByVal Password As
String)
Dim vbProj As VBIDE.VBProject
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
SendKeys "{ESC}"
DoEvents
End Sub
This code works fine when used first time. The problem is, if the user
types the wrong password in, then I call the same routine, it leaves
the Project Properties form on the screen, although it has correctly
unlocked the project.
Can someone please help?
used the following code that I found on the net
Private Sub UnprotectVBProject(WB As Workbook, ByVal Password As
String)
Dim vbProj As VBIDE.VBProject
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
SendKeys "{ESC}"
DoEvents
End Sub
This code works fine when used first time. The problem is, if the user
types the wrong password in, then I call the same routine, it leaves
the Project Properties form on the screen, although it has correctly
unlocked the project.
Can someone please help?