Devi andare nel Vba del foglio1 e cambiare l'indirizzo "$A$1" un "$C$1" così
- Codice: Seleziona tutto
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address <> "$C$5" Then Exit Sub '<<<<< qui
If Passo = 0 Then Controllo_Accesso '<<<< qui ho aggiunto la variabile "Passo" che spiegavo nel post precedente
End Sub
Nel Vba devi aggiungere Passo sia in Public (integer)
- Codice: Seleziona tutto
Option Explicit
Public CPw As Long, Ann, Passo As Integer '<<<<< qui
Public Psw_Amm, PSW As String
Public Ws1 As Worksheet
e aggiungere Passo = 1nella variabile Sproteggi
- Codice: Seleziona tutto
Sub Sproteggi()
Set Ws1 = Worksheets("Foglio1")
Passo = 1
Ws1.Unprotect Password:=Psw_Amm
End Sub
Però dovresti aggiungere in Thisworkbook_Open la protezione del foglio richiamando la macro "Proteggi" in questa maniera
Private Sub Workbook_Open()
proteggi
End Sub
All'apertura del file il foglio sarà protetto
Avendo corretto un bug nella macro ti posto l'intero codice del modulo quindi è consigliabile che copi tutto il codice in questo box e lo sostituisci al precedente.
- Codice: Seleziona tutto
Option Explicit
Public CPw As Long, Ann, Passo As Integer
Public Psw_Amm, PSW As String
Public Ws1 As Worksheet
Sub Controllo_Accesso()
Set Ws1 = Worksheets("Foglio1")
Ws1.Select
Inizio:
Ann = 0
CPw = 0
UserForm1.TextBox1.Value = ""
Psw_Amm = "Pippo"
proteggi
ActiveSheet.EnableSelection = xlUnlockedCells
UserForm1.CommandButton3.Visible = True
UserForm1.TextBox1.Visible = True
UserForm1.Label1.Visible = True
UserForm1.CommandButton1.Visible = True
UserForm1.Show
InizioP:
If Ann = 0 Then
If PSW <> Psw_Amm Then
UserForm1.TextBox1.Value = ""
UserForm1.TextBox1.Visible = True
UserForm1.Label1.Visible = True
UserForm1.CommandButton1.Visible = True
UserForm1.CommandButton3.Visible = False
UserForm1.Show
CPw = CPw + 1
If CPw < 3 Then
MsgBox "Password Errata... Riprova (Controlla maiuscole/minuscole)"
GoTo InizioP
Else
MsgBox "Password Errata per 3 volte - Dgita Utente o annulla"
GoTo Inizio
End If
Else
Sproteggi
End If
End If
End Sub
Sub proteggi()
Set Ws1 = Worksheets("Foglio1")
Ws1.Protect Password:=Psw_Amm, DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowFormattingCells:=True
End Sub
Sub Sproteggi()
Set Ws1 = Worksheets("Foglio1")
Passo = 1
Ws1.Unprotect Password:=Psw_Amm
End Sub
Per sicurezza
Allego il file modificatociao