Option Explicit
Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare PtrSafe Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long
Private Sub ComboBox1_Change()
Me.TextBox1.Text = Me.ComboBox1.List(Me.ComboBox1.ListIndex, 1)
End Sub
Private Sub ComboBox2_Change()
Me.TextBox2.Text = Me.ComboBox2.List(Me.ComboBox2.ListIndex, 1)
End Sub
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub SDate_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single)
With SDate
.SetFocus
.SelStart = 0
.SelLength = Len(SDate.Text)
End With
End Sub
Private Sub SDate_Change()
Dim Valeur As Byte
SDate.MaxLength = 10
End Sub
Private Sub SDate_KeyPress(ByVal Keycode As MSForms.ReturnInteger)
If InStr("0123456789", Chr(Keycode)) = 0 Then Keycode = 0
End Sub
Private Sub SDate_KeyUp(ByVal Keycode As MSForms.ReturnInteger, ByVal Shift As Integer)
Dim Valeur As Byte
If Keycode = 10 Or Keycode = 46 Then Exit Sub
Valeur = Len(SDate)
If Valeur = 2 Or Valeur = 5 Then
SDate = SDate & "/"
End If
If Valeur = 8 Then
If Not IsDate(Me.SDate) Then
MsgBox "Veuillez entrer une date valide."
SDate.Value = ""
Exit Sub
End If
End If
End Sub
Private Sub SDate_Exit(ByVal c As MSForms.ReturnBoolean)
Dim Valeur As Byte
Dim datemois As String
datemois = ActiveSheet.Range("C2")
Valeur = Len(SDate)
If Valeur = 0 Then Exit Sub
If Valeur < 10 Or Valeur = 0 Then
MsgBox "Veuillez entrer une date valide !"
SDate.Value = ""
CreateObject("wscript.shell").SendKeys "+{TAB}", False
ElseIf Mid(SDate.Value, 7, 4) <> Mid(datemois, 7, 4) Then
MsgBox "Veuillez entrer une date valide ou appartenant à la période de " & ActiveSheet.Range("C4").Value & " " & ActiveSheet.Range("C5").Value
SDate.Value = ""
CreateObject("wscript.shell").SendKeys "+{TAB}", False
End If
End Sub
Private Sub SDate_AfterUpdate()
SDate.Value = Format(SDate.Value, "dd/mm/yyyy")
End Sub
Private Sub UserForm_Initialize()
Dim ws As Worksheet, x As String
Dim Drl As Integer, c As Range, a As Double, b As Double, Taille As Double
Dim nb As Integer, nb2 As Integer, nb_max As Integer, nbrow As Long, k As Long, n As Long, n2 As Long, k2 As Long, nb_max2 As Integer
Dim nb_ As Integer, nb2_ As Integer
Dim hwnd As Long
Dim style
Dim i As Integer
Dim j As Integer
Dim TailleCol As Integer
Dim SizeCol As String
hwnd = FindWindow(vbNullString, Me.Caption)
style = GetWindowLong(hwnd, -16) And &HFFF7FFFF
SetWindowLong hwnd, -16, style
DrawMenuBar hwnd
With Sheets("Paramétrage")
With .ListObjects("t_Code")
Me.ComboBox1.RowSource = .DataBodyRange.Address(, , , True)
For j = 1 To 2
For i = 1 To .ListRows.Count
TailleCol = WorksheetFunction.Max(TailleCol, Len(.DataBodyRange(i, j)))
Next i
SizeCol = SizeCol & TailleCol * 8 & ";"
Next j
SizeCol = Left(SizeCol, Len(SizeCol) - 1)
With Me.ComboBox1
.ColumnCount = 2
.ColumnWidths = SizeCol
.Font.Name = "Tahoma"
.Font.Size = 10
.Width = 80
.ListWidth = 300
End With
End With
With .ListObjects("t_Compte")
Me.ComboBox2.RowSource = .DataBodyRange.Address(, , , True)
For j = 1 To 2
For i = 1 To .ListRows.Count
TailleCol = WorksheetFunction.Max(TailleCol, Len(.DataBodyRange(i, j)))
Next i
SizeCol = SizeCol & TailleCol * 8 & ";"
Next j
SizeCol = Left(SizeCol, Len(SizeCol) - 1)
With Me.ComboBox2
.ColumnCount = 2
.ColumnWidths = SizeCol
.Font.Name = "Tahoma"
.Font.Size = 10
.Width = 80
.ListWidth = 300
End With
End With
End With
Me.ComboBox1.ListIndex = 0
Me.ComboBox2.ListIndex = 0
Me.ComboBox1.SetFocus
End Sub