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
| Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Nom_Fichier As String, Texte As Variant, Part As String
Dim NumFile As Integer, Compteur As Integer
Dim off1, off2, i As Integer
Nom_Fichier = "C:\Mes Documents\Xavier\BDD\RU" & Target.Value & ".txt"
Compteur = 1
If Dir(Nom_Fichier) = "" Then
MsgBox "Le fichier est introuvable.", vbCritical + vbOKOnly, "Attention..."
Exit Sub
Else
Worksheets("Feuil2").Select
Worksheets("Feuil2").Cells.Clear
NumFile = FreeFile
Open Nom_Fichier For Input As NumFile
Do While Not EOF(NumFile)
Line Input #NumFile, Texte
off1 = 0
off2 = 0
' If InStr(Texte, Chr(9)) Then
off1 = InStr(Texte, Chr(9))
Worksheets("Feuil2").Cells(Compteur, 1) = Left(Texte, off1 - 1)
For i = 2 To 100
If InStr(off1 + 1, Texte, Chr(9)) Then
off2 = InStr(off1 + 1, Texte, Chr(9))
Worksheets("Feuil2").Cells(Compteur, i) = Mid(Texte, off1 + 1, off2 - off1 - 1)
off1 = off2
Else
Worksheets("Feuil2").Cells(Compteur, i) = Right(Texte, Len(Texte) - off1)
Exit For
End If
Next i
' Else
' Worksheets("Feuil2").Cells(Compteur, 1) = Texte
' End If
Compteur = Compteur + 1
Loop
End If
End Sub |
Partager