En fait je n'avais pas vérifié mais j'ai une erreur à l'exécution, voici mon code dans sa globalité !
Dans ce cas, j'ai erreur d’exécution 458 :
Private Sub CommandButton2_Click()
Static truc '"truc" est une variable pour : si mauvaise réponse, une deuxième chance avant fermeture
If TextBox1.Value = "coucou" Then
'BLABLABLA
End If
If TextBox1.Value = "" Then
'BLABLABLA
End If
If TextBox1.Value <> "" Then
If truc = 0 Then '"truc" est une variable pour : si mauvaise réponse, une deuxième chance avant fermeture
If MsgBox("Concentrez-vous " & Application.UserName & " !", vbExclamation, "Outil Cendre") = vbOK Then
truc = truc + 1
End If
ElseIf truc = 1 Then
Unload Me
If MsgBox("Bien essayé " & Application.UserName & ", mais ce n'est toujours pas ça, au revoir !", vbCritical, "Outil Cendre") = vbOK Then
End If
ActiveWorkbook.Close savechanges:=False
End If
End If
End Sub
Avec cette ligne surlignée :
If TextBox1.Value <> "" Then
Et dans ce cas, j'ai erreur d’exécution 13 :
Private Sub CommandButton2_Click()
Static truc '"truc" est une variable pour : si mauvaise réponse, une deuxième chance avant fermeture
If TextBox1.Value = "coucou" Then
'BLABLABLA
End If
If TextBox1.Value = "" Then
'BLABLABLA
End If
If TextBox1.Value <> "" And "coucou" Then
If truc = 0 Then '"truc" est une variable pour : si mauvaise réponse, une deuxième chance avant fermeture
If MsgBox("Concentrez-vous " & Application.UserName & " !", vbExclamation, "Outil Cendre") = vbOK Then
truc = truc + 1
End If
ElseIf truc = 1 Then
Unload Me
If MsgBox("Bien essayé " & Application.UserName & ", mais ce n'est toujours pas ça, au revoir !", vbCritical, "Outil Cendre") = vbOK Then
End If
ActiveWorkbook.Close savechanges:=False
End If
End If
End Sub
Avec cette ligne surlignée :
If TextBox1.Value <> "" And "coucou" Then