Bonjour tout le monde,
j'ai une macro qui récupère certaines données provenant d'un fichier texte, le problèmes c'est que quand ce fichier texte n'existe pas mon programme bug. j'ai essayer avec la commande :
On Error Resume Next
ça marche pas . quelqu'un aurai une petite idée svp. merci d'avance.
j'ai une macro qui récupère certaines données provenant d'un fichier texte, le problèmes c'est que quand ce fichier texte n'existe pas mon programme bug. j'ai essayer avec la commande :
On Error Resume Next
ça marche pas . quelqu'un aurai une petite idée svp. merci d'avance.
Code:
Sub DerLigne()
Dim Tbl() As String
Dim Ligne As String
Dim I As Integer
Dim txt As String
'adapter le chemin et nom du fichier
txt = ""
'If Fichier = "" Then
' il faut calculer en fonction de la date
Fichier = "a" & Format(Date, "yyyymmdd") & ".TXT"
chemin = "\\193.50.118.63\data\"
'If Fichier <> "" Then
'End If
On Error Resume Next
'Open "\\193.50.118.63\data\a20130612.txt" For Input As #1
Open chemin & Fichier For Input As #1
Do While Not EOF(1)
Line Input #1, Ligne
txt = txt & Ligne & vbCrLf
Loop
Close #1
'résultat dans la fenêtre d'exécution (Ctrl+G)
' Debug.Print Tbl(I)
Tbl = Split(txt, vbCrLf)
For I = UBound(Tbl) To 0 Step -1
If Trim("" & Tbl(I)) <> "" Then
Tbl = Split(Tbl(I), Chr(9))
Range(Cells(4, 1), Cells(4, UBound(Tbl))) = Tbl()
Exit For
End If
Next
end Sub