Bonjour à tous,
J'ai essayé 50 fois de faire fonctionner le code ci-dessous proposé par bbil pour protéger puis déprotéger le projet vba.
Mais rien n'y fait, ma procédure s'arrête inévitablement sur la fenêtre des propriétés du projet, nécessitant un appui manuel sur la touche [ENTER]
Ceci se produit à la deprotection ainsi qu'à la reprotection. Quelqu'un aurait une idée ?
Merci à vous
Et voici mon code adapté :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 Sub TestProtect() ProtectVBProject Workbooks("Proteger_deproteger.xls"), "motdepasse" End Sub Sub TestUnprotect() UnprotectVBProject Workbooks("Proteger_deproteger.xls"), "motdepasse" End Sub Sub UnprotectVBProject(WB As Workbook, ByVal Password As String) Dim vbProj As Object Set vbProj = WB.VBProject If vbProj.Protection <> 1 Then Exit Sub Set Application.VBE.ActiveVBProject = vbProj 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 If vbProj.Protection = 1 Then Exit Sub Set Application.VBE.ActiveVBProject = vbProj SendKeys "+{TAB}{RIGHT}%V{+}{TAB}" & Password & "{TAB}" & _ Password & "~" Application.VBE.CommandBars(1).FindControl(ID:=2578, recursive:=True).Execute WB.Save End Sub
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 Sub UnprotectVBProject(WB As Workbook, ByVal PwD As String) Dim vbProj As Object Set vbProj = WB.VBProject If vbProj.Protection <> 1 Then Exit Sub Set Application.VBE.ActiveVBProject = vbProj SendKeys PwD & "~~" Application.VBE.CommandBars(1).FindControl(ID:=2578, recursive:=True).Execute End Sub Sub ProtectVBProject(WB As Workbook, ByVal PwD 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 SendKeys "+{TAB}{RIGHT}%V{+}{TAB}" & PwD & "{TAB}" & PwD & "~" Application.VBE.CommandBars(1).FindControl(ID:=2578, recursive:=True).Execute ' WB.Save End Sub
Partager