verrouiller / déverrouiller

kinel

XLDnaute Occasionnel
bonsoir le forum

j'utilise un userform pour verrouiller et déverrouiller une feuille
dans cet userform se trouve un bouton OK dont voici le code :

Sub Ok_Click()
If Application.CommandBars("Worksheet Menu Bar").Enabled = True Then
If Identification.TextBox1.Value = "ml" Then
Application.DisplayFullScreen = True
With Application
.CommandBars("Worksheet Menu Bar").Enabled = False

With .CommandBars("Standard")
.Enabled = False
.Visible = False

End With
End With
End If
Identification.Hide

Exit Sub
End If

If Application.CommandBars("Worksheet Menu Bar").Enabled = False Then
If Identification.TextBox1.Value = "ml" Then
Application.DisplayFullScreen = False
With Application
.CommandBars("Worksheet Menu Bar").Enabled = True

With .CommandBars("Standard")
.Enabled = True
.Visible = True

End With
End With
End If
Identification.Hide

Exit Sub
End If

End Sub


les deux commandes suivantes vont me permettre :

1. de protéger et de limiter la zone de travail
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowFormattingRows:=True
ActiveSheet.ScrollArea = "A1:N43"

2. d'ôter la protection et d'ouvrir la zone de travail
ActiveSheet.Unprotect
ActiveSheet.ScrollArea = ""

un membre du forum peux t il m'aider à placer ces deux commandes dans le code du bouton OK ?

merci de votre aide

Kinel
 

ayaflo

XLDnaute Junior
Re : verrouiller / déverrouiller

Salut Kinel,

Je les placerais dans les IF qui font référence au test du mot de passe.

Je n'ai pas testé, mais voici le code :
Sub Ok_Click()
If Application.CommandBars("Worksheet Menu Bar").Enabled = True Then
If Identification.TextBox1.Value = "ml" Then
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowFormattingRows:=True
ActiveSheet.ScrollArea = "A1:N43"
Application.DisplayFullScreen = True
With Application
.CommandBars("Worksheet Menu Bar").Enabled = False

With .CommandBars("Standard")
.Enabled = False
.Visible = False

End With
End With

End If
Identification.Hide



Exit Sub
End If

If Application.CommandBars("Worksheet Menu Bar").Enabled = False Then
If Identification.TextBox1.Value = "ml" Then
Application.DisplayFullScreen = False
With Application
.CommandBars("Worksheet Menu Bar").Enabled = True

With .CommandBars("Standard")
.Enabled = True
.Visible = True

End With
End With
ActiveSheet.Unprotect
ActiveSheet.ScrollArea = ""
End If
Identification.Hide

Exit Sub
End If

End Sub

A+
 

Discussions similaires