Bonjour à tous !
Voilà, je travaille sur un projet avec mot de passe mais au lancement de mon fichier, je veux importer un module de l´extérieur donc je désactive la protection, j´importe puis je la réactive, voici le code :
Les fonctions d´activation et de désactivation sont ici :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 Private Sub Workbook_Open() 'Désactive la protection UnprotectVBProject ThisWorkbook, "pass" DoEvents 'on Importe ImportModul 'On réactive la protection ProtectVBProject ThisWorkbook, "pass" DoEvents End Sub
Tout semble bien marcher mais le problème c´est qu´après ces procédures, je fais ALT + F11 et je peux accéder au code sans rentrer de mot de passe ! Pourtant quand je regarde les propriétés du projet, il y a bien un mot de passe. (les fonctions ont bien marché). Mais vu qu´il s´est déjà ouvert avec le mot de passe, il pense que c´est bon alors que je voudrais qu´il me le demande
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 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 SendKeys to set the project password SendKeys "+{TAB}{RIGHT}%V{+}{TAB}" & Password & "{TAB}" & _ Password & "~" Application.VBE.CommandBars(1).FindControl(ID:=2578, recursive:=True).Execute End Sub
Quelqu´un a-t-il une solution à mon problème ?
Merci d´avance de votre aide
@ +
Partager