Inserer un mot de passe dans macro existante
Résolu
Eaheru
Messages postés
197
Date d'inscription
Statut
Membre
Dernière intervention
-
Eaheru Messages postés 197 Date d'inscription Statut Membre Dernière intervention -
Eaheru Messages postés 197 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
Eriic, m'avait proposé cette macro :
Private Sub Worksheet_Change(ByVal Target As Range)
Dim lig As Long
lig = Target.Row
If lig = 1 Then Exit Sub 'non actif sur ligne 1
ActiveSheet.Unprotect
Cells(lig, 9).Locked = Not (Application.CountA(Cells(lig, 1).Resize(1, 8)) = 8)
If Not Intersect(Target, Cells(lig, 2).Resize(1, 7)) Is Nothing Then
If Application.CountA(Cells(lig, 2).Resize(1, 7)) = 7 Then
Cells(lig, 1) = Now()
Else
Cells(lig, 1) = ""
End If
ElseIf Not Intersect(Target, Range("I" & lig)) Is Nothing Then
Cells(lig, 1).Resize(1, 8).Locked = (Cells(lig, 9) <> "")
Cells(lig, 10) = Now()
End If
ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=False
ActiveSheet.EnableSelection = xlUnlockedCells
End Sub
Qui répond parfaitement aux questions que j'avais posé :
https://forums.commentcamarche.net/forum/affich-18239601-tests-sur-conditions-multiples-excel-2007
et
https://forums.commentcamarche.net/forum/affich-18240519-fonctionnalite-macro-excel-sur-ligne-inseree
Toutefois, et c'est la que je vois mes rapide limites en VBA, la macro effectue une protection de la feuille uniquement avec un mot de passe vierge.
Ma Question est donc : Dans cette macro, ou puis je insérer un mot de passe bien défini svp ?
Merci d'avance pour votre aide.
Eriic, m'avait proposé cette macro :
Private Sub Worksheet_Change(ByVal Target As Range)
Dim lig As Long
lig = Target.Row
If lig = 1 Then Exit Sub 'non actif sur ligne 1
ActiveSheet.Unprotect
Cells(lig, 9).Locked = Not (Application.CountA(Cells(lig, 1).Resize(1, 8)) = 8)
If Not Intersect(Target, Cells(lig, 2).Resize(1, 7)) Is Nothing Then
If Application.CountA(Cells(lig, 2).Resize(1, 7)) = 7 Then
Cells(lig, 1) = Now()
Else
Cells(lig, 1) = ""
End If
ElseIf Not Intersect(Target, Range("I" & lig)) Is Nothing Then
Cells(lig, 1).Resize(1, 8).Locked = (Cells(lig, 9) <> "")
Cells(lig, 10) = Now()
End If
ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=False
ActiveSheet.EnableSelection = xlUnlockedCells
End Sub
Qui répond parfaitement aux questions que j'avais posé :
https://forums.commentcamarche.net/forum/affich-18239601-tests-sur-conditions-multiples-excel-2007
et
https://forums.commentcamarche.net/forum/affich-18240519-fonctionnalite-macro-excel-sur-ligne-inseree
Toutefois, et c'est la que je vois mes rapide limites en VBA, la macro effectue une protection de la feuille uniquement avec un mot de passe vierge.
Ma Question est donc : Dans cette macro, ou puis je insérer un mot de passe bien défini svp ?
Merci d'avance pour votre aide.
A voir également:
- Inserer un mot de passe dans macro existante
- Trousseau mot de passe iphone - Guide
- Mot de passe - Guide
- Mot de passe administrateur - Guide
- Mot de passe bios perdu - Guide
- Voir mot de passe wifi android - Guide
1 réponse
A final j'ai trouvé, je le post au cas ou cela puisse dépanner quelqu'un :
'Option Explicit
'Private Sub Worksheet_Change(ByVal Target As Range)
' Dim lig As Long
' lig = Target.Row
' If lig = 1 Then Exit Sub 'non actif sur ligne 1
' ActiveSheet.Unprotect Password:="test"
' Cells(lig, 11).Locked = Not (Application.CountA(Cells(lig, 1).Resize(1, 8)) = 8)
' If Not Intersect(Target, Cells(lig, 2).Resize(1, 7)) Is Nothing Then
' If Application.CountA(Cells(lig, 2).Resize(1, 7)) = 7 Then
' Cells(lig, 1) = Now()
' Else
' Cells(lig, 1) = ""
' End If
' ElseIf Not Intersect(Target, Range("I" & lig)) Is Nothing Then
' Cells(lig, 1).Resize(1, 10).Locked = (Cells(lig, 9) <> "")
' Cells(lig, 10) = Now()
' End If
' ActiveSheet.Protect Password:="test", DrawingObjects:=False, Contents:=True, Scenarios:=False
' ActiveSheet.EnableSelection = xlUnlockedCells
'End Sub
'Option Explicit
'Private Sub Worksheet_Change(ByVal Target As Range)
' Dim lig As Long
' lig = Target.Row
' If lig = 1 Then Exit Sub 'non actif sur ligne 1
' ActiveSheet.Unprotect Password:="test"
' Cells(lig, 11).Locked = Not (Application.CountA(Cells(lig, 1).Resize(1, 8)) = 8)
' If Not Intersect(Target, Cells(lig, 2).Resize(1, 7)) Is Nothing Then
' If Application.CountA(Cells(lig, 2).Resize(1, 7)) = 7 Then
' Cells(lig, 1) = Now()
' Else
' Cells(lig, 1) = ""
' End If
' ElseIf Not Intersect(Target, Range("I" & lig)) Is Nothing Then
' Cells(lig, 1).Resize(1, 10).Locked = (Cells(lig, 9) <> "")
' Cells(lig, 10) = Now()
' End If
' ActiveSheet.Protect Password:="test", DrawingObjects:=False, Contents:=True, Scenarios:=False
' ActiveSheet.EnableSelection = xlUnlockedCells
'End Sub