1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| Option Explicit
Dim plusHligne
Const widthcolonne = "50 pt;100 pt;120 pt;60 pt;80 pt"
' donc pour les left colonnes c'est 0,50,150,250,310
Dim colwidth
Dim actiVcoL
Dim colleft()
Private Sub ListBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Dim Mot$
With ListBox1
Select Case KeyCode
Case 8
KeyCode = 0
Mot = .List(.ListIndex, actiVcoL): .List(.ListIndex, actiVcoL) = Mid(Mot, 1, Len(Mot) - 1)
Case 9, 39
KeyCode = 0
If actiVcoL = 4 Then Exit Sub
actiVcoL = actiVcoL + 1: repere.Left = .Left + colleft(actiVcoL): repere.Width = colwidth(actiVcoL)
Case 37
KeyCode = 0
If actiVcoL = 0 Then Exit Sub
actiVcoL = actiVcoL - 1
repere.Left = .Left + colleft(actiVcoL): repere.Width = colwidth(actiVcoL)
Case 13
KeyCode = 0: .AddItem: .Height = IIf(.ListCount * (.Font.Size * 1.25) > 205, 205, .Height + plusHligne)
.ListIndex = .ListCount - 1
End Select
End With
End Sub
Private Sub ListBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
With ListBox1
.List(.ListIndex, actiVcoL) = .List(.ListIndex, actiVcoL) & Chr(KeyAscii)
End With
End Sub
Private Sub ListBox1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Dim i#
For i = 0 To UBound(colleft)
If X > colleft(i) Then repere.Left = ListBox1.Left + colleft(i): repere.Width = colwidth(i): actiVcoL = i
Next
repere.Caption = "Colonne " & actiVcoL
End Sub
Private Sub ListBox1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Dim i#
For i = 0 To UBound(colleft)
If X > colleft(i) Then repere.Left = ListBox1.Left + colleft(i): repere.Width = colwidth(i): actiVcoL = i
Next
repere.Caption = "Colonne " & actiVcoL
End Sub
Private Sub UserForm_Activate()
Dim i#, X#
colwidth = Split(Replace(widthcolonne, " pt", ""), ";") ' tableau des largeur des colonnes de la listbox
ReDim colleft(UBound(colwidth)): colleft(0) = 0
For i = 1 To UBound(colwidth): X = X + Val(colwidth(i - 1)): colleft(i) = X: Next ' memorisation des left colonnes pour le guide rouge
With ListBox1: .ColumnCount = 5: .AddItem: .ColumnWidths = widthcolonne: plusHligne = .Font.Size * 1.25: End With
End Sub |
Partager