1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
'===================== Sub TestUnprotect()
Dim S
S = "TestMdpxl97.xls"
UnprotectVBProject Workbooks(S), "zaza"
'pour qu'Excel reconnaisse la nouvelle situation (déprotection)
DoEvents
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:%78, recursive:=True).Execute
End Sub |
Partager