protéger Projet VBA par mot de passe grâce à une macro

Oranger

XLDnaute Occasionnel
Bonjour,

Je chercher à protéger par mot de passe un projet VBA. j'ai trouvé sur internet le code suivant de Bill Manville mais ça ne fonctionne pas:

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 lovely SendKeys to set the project password
SendKeys "+{TAB}{RIGHT}%V{+}{TAB}" & Password & "{TAB}" & _
Password & "~"

Application.VBE.CommandBars(1).FindControl(ID:%78,
recursive:=True).Execute

WB.Save
End Sub

Quelqu'un aurait il des indications sur comment faire pour protéger un projet VBA d'un classeur?
 

stefan373

XLDnaute Occasionnel
Bonjour oranger et le forum.

Il faut aller dans le VBA (ALT + F11), puis clic droit sur microsoft excel objet dans fenêtre de gauche puis propriétés de VBAProject
puis prtection et vous y voilà.

A +

Edit bonjour pierrot et encore en retard. :)
 

Oranger

XLDnaute Occasionnel
Re : protéger Projet VBA par mot de passe grâce à une macro

Bonjour,

Je joins mon fichier afin de vous montrer mon code
 

Pièces jointes

  • Classeur1.xls
    20.5 KB · Affichages: 270
  • Classeur1.xls
    20.5 KB · Affichages: 292
  • Classeur1.xls
    20.5 KB · Affichages: 303

Pierrot93

XLDnaute Barbatruc
Re : protéger Projet VBA par mot de passe grâce à une macro

Re,

dans ta déclaration de procédure, "workbook" sans s
Code:
Sub ProtectVBProject(WB As Workbook, ByVal Password As String)

A noter, ton code serait mieux placer dans un module standard plutôt que dans le module d'une feuille.....
 

Oranger

XLDnaute Occasionnel
Re : protéger Projet VBA par mot de passe grâce à une macro

Le code ne fonctionne pas. Voilà ce que j'obtiens dans mon code:

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 lovely SendKeys to set the project password
SendKeys "+{TAB}{RIGHT}%V{+}{TAB}" & Password & "{TAB}" & _
Password & "~"

epasse motdepasse
Application.VBE.CommandBars(1).FindControl(ID:=78, recursive:=True).Execute

WB.Save
End Sub

Le sendkey écrit mot de passe dans mon code et mon projet n'est pas protégé :s
 

Discussions similaires

C
Réponses
0
Affichages
1 K
Compte Supprimé 979
C

Statistiques des forums

Discussions
311 720
Messages
2 081 892
Membres
101 831
dernier inscrit
gillec