Thread: Unlock VBE
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Unlock VBE

Bill's code relies on you knowing the password.

If you don't know the password, then I wouldn't think this approach would be
very effective.

Brettjg wrote:

Is there any new information on how to unlock a VBE Project when you don't
know the password? I've tried Bill Manvilee's code but even though I've got
the extensibility checked, I can't even assign that UnprotectVBProject macro
to anything (macro doesn't show up on the list of available macros). I can
run the "test" macro ok, but it just comes up asking for a password to th
NSC.xls VBE.

Code used is as follows:
Sub test()
UnprotectVBProject Workbooks("NSC.xls"), "password"
End Sub

Sub UnprotectVBProject(WB As Workbook, ByVal Password As String)
'
' Bill Manville, 29-Jan-2000
'
Dim VBP As VBProject, oWin As VBIDE.Window
Dim wbActive As Workbook
Dim i As Integer

Set VBP = WB.VBProject
Set wbActive = ActiveWorkbook

If VBP.Protection < vbext_pp_locked Then Exit Sub

Application.ScreenUpdating = False

' Close any code windows To ensure we hit the right project
For Each oWin In VBP.VBE.Windows
If InStr(oWin.Caption, "(") 0 Then oWin.Close
Next oWin

WB.Activate
' now use lovely SendKeys To unprotect
Application.OnKey "%{F11}"
SendKeys "%{F11}%TE" & Password & "~~%{F11}", True

If VBP.Protection = vbext_pp_locked Then
' failed - maybe wrong password
SendKeys "%{F11}%TE", True
End If

' leave no evidence of the password
Password = ""
' go back To the previously active workbook
wbActive.Activate

End Sub

Thanks, Brett


--

Dave Peterson