Bonsoir Lio, Justine, Philippe, Eric, le Forum
Je partage tout à fait ton avis Lio. C'est d'ailleurs sûrement pour cette raison que Philippe ne s'est pas rendu compte de cette boucle :
Private Declare Function FindWindow Lib 'user32' Alias 'FindWindowA' (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowLong Lib 'user32' Alias 'GetWindowLongA' (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib 'user32' Alias 'SetWindowLongA' (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function DrawMenuBar Lib 'user32' (ByVal hWnd As Long) As Long
Private Declare Function SendMessage Lib 'user32' Alias 'SendMessageA' (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function ReleaseCapture Lib 'user32' () As Long
Private Sub CommandButton1_Click()
With Sheets('feuil2')
Range('A1') = TextBox1.Value
End Sub
Private Sub UserForm_Click()
End Sub
Private Sub UserForm_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Unload Me
End Sub
Private Sub UserForm_MouseDown(ByVal Button As Integer _
, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
ReleaseCapture
SendMessage FindWindow(vbNullString, Me.Caption), &HA1, 2, 0&
End Sub
Private Sub UserForm_Initialize()
With Sheets('feuil2')
TextBox1.Value = Range('A1')
End With
Dim i As Byte
For i = 1 To 8
Controls('textbox' & i).Enabled = False
Next i
Dim hWnd As Long, Style As Long
hWnd = FindWindow(vbNullString, Me.Caption)
Style = GetWindowLong(hWnd, -16) And Not &HC00000
SetWindowLong hWnd, -16, Style
DrawMenuBar hWnd
End Sub
Au milieu de tout ce bazar d'appel API qu'il ne doit pas vraiment maîtriser.
En fait ce UserForm dans l'état n'aurait besoin que de ceci :
Option Explicit
Private Sub UserForm_Initialize()
With Sheets('feuil2')
TextBox1.Value = .Range('A1')
End With
End Sub
Private Sub CommandButton1_Click()
With Sheets('feuil2')
.Range('A1') = TextBox1.Value
End With
End Sub
Et éventuellement pour éviter de fermer le UserForm par la Croix :
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
MsgBox 'Cette commande ne peut être exécutée, Veuillez fermer le logiciel avec le bouton prevu a cet effect !!.'
Cancel = True
End If
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub
Bonne Soirée
[ol]@+Thierry[/ol]