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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
| Private Sub UserForm_Initialize()
Call Init
End Sub
Private Sub Init()
'Ouverture du fichier de sauvegarde
Open "D:\toto" For Append As #1
Close #1
'Chargement du chemin de sortie
Open "D:\toto" For Input As #1
While Not EOF(1)
Input #1, a
If LenB(a) <> 0 Then
Me.TextBox1.Text = a
End If
Wend
Close #1
'Par défaut on récupère le chemin du bureau de l'utilisateur
'par le biais de la fonction contenue dans le module Special_Path
If TextBox1.Text = vbNullString Then TextBox1.Text = GetSpecialfolder(CSIDL_DESKTOP)
FlagE:
On Error Resume Next
'Fermeture du fichier s'il est ouvert
'et ouverture de celui-ci en lecture seule
Windows("fichier.xls").Close (False)
On Error Resume Next
ThisWorkbook.FollowHyperlink ("https://lien_vers_fichier"), , True
If Err.Number <> 0 Then MsgBox "Adresse incorrecte"
Err.Clear
'bug : problème de chemin , de temps de chargement ?
Windows("fichier.xls").Activate
Windows("fichier.xls").Application.ScreenUpdating = False
'Geston de l'erreur 1004 si le fichier est introuvable ou si le champ Input data est vide
If Err.Number = 1004 Then
MsgBox "Error: file not found.", vbExclamation
UserForm1.MultiPage1.Value = 1
End If
Me.MultiPage1.Value = 0
'Init de variable
Ligne = Cells.Range("A2").End(xlDown).Row
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Code permettant l'affichage dans la listbox et le filtrage
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
With Worksheets(1)
Me.ListBox1.Clear
Me.vList.ColumnCount = 13
Me.vList.List = Range("A2:M" & Ligne).Value '"A2:L" & Ligne
With Me.ListBox1
.ColumnWidths = 130
.ColumnCount = 2
.RowSource = "A2:B" & Ligne
End With
Call TextBox2_Change
'On met le focus sur le champ de filtrage
Me.MultiPage1.SetFocus
Me.TextBox2.SetFocus
End With
''''''''''''''''''''
''''''''''''''''''''
'On minimise la fenêtre
Windows("fichier.xls").Visible = False
Windows("fichier.xls").Application.ScreenUpdating = True
Me.TextBox2.SetFocus
End Sub
Private Sub TextBox2_Change()
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Update de l'affichage de la liste en fonction des valeurs tappées'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Init de la variable contenant les caractères à filtrer
strLetter = Me.TextBox2.Text
'On efface la liste
ListBox1.RowSource = vbNullString
'Init correspondant à la ligne 2 de la source xls
L = 1
'Boucle permettant le rafraichissement de la listbox à chaque caractère tapé
For L = 1 To vList.ListCount - 1
If InStrRev(vList.List(L), strLetter, -1, vbTextCompare) <> 0 Then
Li = ListBox1.ListCount
If vList.List(L, 2) <> "N" Then
With Me.ListBox1
.AddItem
.List(Li, 0) = Me.vList.List(L, 0)
.List(Li, 1) = Me.vList.List(L, 1)
End With
End If
End If
Next L
'Init
Ligne2 = Me.ListBox1.ListCount
End Sub |
Partager