dionys0s
XLDnaute Impliqué
Bonjour le forum
J'ai un classeur dont l'accès au code est protégé par mot de passe. J'aimerais savoir s'il existe un moyen de déverrouiller et verrouiller le projet par macro.
J'ai bien trouvé ce code pour la protection mais son exécution plante :
	
	
	
	
	
		
D'avance, merci pour votre aide !
	
		
			
		
		
	
				
			J'ai un classeur dont l'accès au code est protégé par mot de passe. J'aimerais savoir s'il existe un moyen de déverrouiller et verrouiller le projet par macro.
J'ai bien trouvé ce code pour la protection mais son exécution plante :
		VB:
	
	
	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
  Application.VBE.CommandBars(1).FindControl(ID:=78, Recursive:=True).Execute 'La macro plante sur cette ligne
  SendKeys "+{TAB}{RIGHT}%V{+}{TAB}" & Password & "{TAB}" & Password & "~", True
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
  Application.VBE.CommandBars(1).FindControl(ID:=78, Recursive:=True).Execute 'La macro plante sur cette ligne
  SendKeys Password & "~"
  SendKeys "~"
End Sub
	D'avance, merci pour votre aide !