J'essaye de récupérer des lignes dans un fichier text mais le problème est
que lorsque j'ai une virgule dans ma ligne, ma macro me detect un retour à
la ligne : que dois-je faire ?
Sub LoadFichierText(FichierIni As String)
Dim MaLigneIni As String
If Dir(FichierIni) <> "" Then
On Error GoTo ErreurIniCartouche
Open FichierIni For Input As #1
i = 1
Do Until EOF(1)
Input #1, MaLigneIni
Select Case i
Case 5
Me.TextBoxEquipe.Value = MaLigneIni
Case 8
Me.TextBoxNU.Value = MaLigneIni
Case 11
Me.TextBoxDesignation.Value = MaLigneIni
Case 14
Me.TextBoxIND1.Value = MaLigneIni
Case 15
Me.TextBoxIND2.Value = MaLigneIni
Case 16
Me.TextBoxIND3.Value = MaLigneIni
Case 17
Me.TextBoxIND4.Value = MaLigneIni
Case 20
Me.TextBoxDate1.Value = MaLigneIni
Case 21
Me.TextBoxDate2.Value = MaLigneIni
Case 22
Me.TextBoxDate3.Value = MaLigneIni
Case 23
Me.TextBoxDate4.Value = MaLigneIni
Case 26
Me.TextBoxObjet1.Value = MaLigneIni
Case 27
Me.TextBoxObjet2.Value = MaLigneIni
Case 28
Me.TextBoxObjet3.Value = MaLigneIni
Case 29
Me.TextBoxObjet4.Value = MaLigneIni
Case 32
Me.TextBoxAuteur1.Value = MaLigneIni
Case 33
Me.TextBoxAuteur2.Value = MaLigneIni
Case 34
Me.TextBoxAuteur3.Value = MaLigneIni
Case 35
Me.TextBoxAuteur4.Value = MaLigneIni
Case 38
Me.TextBoxVerif1.Value = MaLigneIni
Case 39
Me.TextBoxVerif2.Value = MaLigneIni
Case 40
Me.TextBoxVerif3.Value = MaLigneIni
Case 41
Me.TextBoxVerif4.Value = MaLigneIni
End Select
i = i + 1
Loop
Close #1
End If
Exit Sub
ErreurIniCartouche:
MsgBox ("Erreur de lecture sur le fichier : " + FichierText)
End
' Créer un objet FileSystem Set fso = CreateObject("Scripting.FileSystemObject")
' Pointer le fichier à traiter Set f = fso.GetFile(nom_fich)
' Ouvrir le fichier Set MyFile = f.OpenAsTextStream(ForReading, TristateUseDefault)
Do While MyFile.AtEndofstream <> True ligne = MyFile.ReadLine 'Lit la ligne ici Loop
' Fermer les fichier MyFile.Close
Set MyFile = Nothing Set fso = Nothing
End Sub
Phil
Damien Kergosien
Bonjour Emcy
utilise Line Input à la place de Input
extrait de l'aide : "Les données lues dans un fichier à l'aide de l'instruction Line Input # sont généralement écrites à l'aide de l'instruction Print #.
L'instruction Line Input # lit un à un les caractères d'un fichier jusqu'au premier retour chariot (Chr(13)) ou retour chariot - saut de ligne (Chr(13) + Chr(10)) rencontré. Les séquences retour chariot - saut de ligne ne sont pas prises en compte (elles ne sont pas ajoutées à la chaîne de caractères)."
Damien
Bonjours,
J'essaye de récupérer des lignes dans un fichier text mais le problème est que lorsque j'ai une virgule dans ma ligne, ma macro me detect un retour à la ligne : que dois-je faire ?
Sub LoadFichierText(FichierIni As String)
Dim MaLigneIni As String
If Dir(FichierIni) <> "" Then
On Error GoTo ErreurIniCartouche Open FichierIni For Input As #1
i = 1
Do Until EOF(1) Input #1, MaLigneIni
Select Case i Case 5 Me.TextBoxEquipe.Value = MaLigneIni
Case 8 Me.TextBoxNU.Value = MaLigneIni
Case 11 Me.TextBoxDesignation.Value = MaLigneIni
Case 14 Me.TextBoxIND1.Value = MaLigneIni Case 15 Me.TextBoxIND2.Value = MaLigneIni Case 16 Me.TextBoxIND3.Value = MaLigneIni Case 17 Me.TextBoxIND4.Value = MaLigneIni
Case 20 Me.TextBoxDate1.Value = MaLigneIni Case 21 Me.TextBoxDate2.Value = MaLigneIni Case 22 Me.TextBoxDate3.Value = MaLigneIni Case 23 Me.TextBoxDate4.Value = MaLigneIni
Case 26 Me.TextBoxObjet1.Value = MaLigneIni Case 27 Me.TextBoxObjet2.Value = MaLigneIni Case 28 Me.TextBoxObjet3.Value = MaLigneIni Case 29 Me.TextBoxObjet4.Value = MaLigneIni
Case 32 Me.TextBoxAuteur1.Value = MaLigneIni Case 33 Me.TextBoxAuteur2.Value = MaLigneIni Case 34 Me.TextBoxAuteur3.Value = MaLigneIni Case 35 Me.TextBoxAuteur4.Value = MaLigneIni
Case 38 Me.TextBoxVerif1.Value = MaLigneIni Case 39 Me.TextBoxVerif2.Value = MaLigneIni Case 40 Me.TextBoxVerif3.Value = MaLigneIni Case 41 Me.TextBoxVerif4.Value = MaLigneIni End Select
i = i + 1 Loop Close #1
End If
Exit Sub
ErreurIniCartouche: MsgBox ("Erreur de lecture sur le fichier : " + FichierText) End
End Sub
End Sub
Bonjour Emcy
utilise Line Input à la place de Input
extrait de l'aide :
"Les données lues dans un fichier à l'aide de l'instruction Line Input
# sont généralement écrites à l'aide de l'instruction Print #.
L'instruction Line Input # lit un à un les caractères d'un fichier
jusqu'au premier retour chariot (Chr(13)) ou retour chariot - saut de
ligne (Chr(13) + Chr(10)) rencontré. Les séquences retour chariot -
saut de ligne ne sont pas prises en compte (elles ne sont pas ajoutées
à la chaîne de caractères)."
Damien
Bonjours,
J'essaye de récupérer des lignes dans un fichier text mais le problème est
que lorsque j'ai une virgule dans ma ligne, ma macro me detect un retour à
la ligne : que dois-je faire ?
Sub LoadFichierText(FichierIni As String)
Dim MaLigneIni As String
If Dir(FichierIni) <> "" Then
On Error GoTo ErreurIniCartouche
Open FichierIni For Input As #1
i = 1
Do Until EOF(1)
Input #1, MaLigneIni
Select Case i
Case 5
Me.TextBoxEquipe.Value = MaLigneIni
Case 8
Me.TextBoxNU.Value = MaLigneIni
Case 11
Me.TextBoxDesignation.Value = MaLigneIni
Case 14
Me.TextBoxIND1.Value = MaLigneIni
Case 15
Me.TextBoxIND2.Value = MaLigneIni
Case 16
Me.TextBoxIND3.Value = MaLigneIni
Case 17
Me.TextBoxIND4.Value = MaLigneIni
Case 20
Me.TextBoxDate1.Value = MaLigneIni
Case 21
Me.TextBoxDate2.Value = MaLigneIni
Case 22
Me.TextBoxDate3.Value = MaLigneIni
Case 23
Me.TextBoxDate4.Value = MaLigneIni
Case 26
Me.TextBoxObjet1.Value = MaLigneIni
Case 27
Me.TextBoxObjet2.Value = MaLigneIni
Case 28
Me.TextBoxObjet3.Value = MaLigneIni
Case 29
Me.TextBoxObjet4.Value = MaLigneIni
Case 32
Me.TextBoxAuteur1.Value = MaLigneIni
Case 33
Me.TextBoxAuteur2.Value = MaLigneIni
Case 34
Me.TextBoxAuteur3.Value = MaLigneIni
Case 35
Me.TextBoxAuteur4.Value = MaLigneIni
Case 38
Me.TextBoxVerif1.Value = MaLigneIni
Case 39
Me.TextBoxVerif2.Value = MaLigneIni
Case 40
Me.TextBoxVerif3.Value = MaLigneIni
Case 41
Me.TextBoxVerif4.Value = MaLigneIni
End Select
i = i + 1
Loop
Close #1
End If
Exit Sub
ErreurIniCartouche:
MsgBox ("Erreur de lecture sur le fichier : " + FichierText)
End
extrait de l'aide : "Les données lues dans un fichier à l'aide de l'instruction Line Input # sont généralement écrites à l'aide de l'instruction Print #.
L'instruction Line Input # lit un à un les caractères d'un fichier jusqu'au premier retour chariot (Chr(13)) ou retour chariot - saut de ligne (Chr(13) + Chr(10)) rencontré. Les séquences retour chariot - saut de ligne ne sont pas prises en compte (elles ne sont pas ajoutées à la chaîne de caractères)."
Damien
Bonjours,
J'essaye de récupérer des lignes dans un fichier text mais le problème est que lorsque j'ai une virgule dans ma ligne, ma macro me detect un retour à la ligne : que dois-je faire ?
Sub LoadFichierText(FichierIni As String)
Dim MaLigneIni As String
If Dir(FichierIni) <> "" Then
On Error GoTo ErreurIniCartouche Open FichierIni For Input As #1
i = 1
Do Until EOF(1) Input #1, MaLigneIni
Select Case i Case 5 Me.TextBoxEquipe.Value = MaLigneIni
Case 8 Me.TextBoxNU.Value = MaLigneIni
Case 11 Me.TextBoxDesignation.Value = MaLigneIni
Case 14 Me.TextBoxIND1.Value = MaLigneIni Case 15 Me.TextBoxIND2.Value = MaLigneIni Case 16 Me.TextBoxIND3.Value = MaLigneIni Case 17 Me.TextBoxIND4.Value = MaLigneIni
Case 20 Me.TextBoxDate1.Value = MaLigneIni Case 21 Me.TextBoxDate2.Value = MaLigneIni Case 22 Me.TextBoxDate3.Value = MaLigneIni Case 23 Me.TextBoxDate4.Value = MaLigneIni
Case 26 Me.TextBoxObjet1.Value = MaLigneIni Case 27 Me.TextBoxObjet2.Value = MaLigneIni Case 28 Me.TextBoxObjet3.Value = MaLigneIni Case 29 Me.TextBoxObjet4.Value = MaLigneIni
Case 32 Me.TextBoxAuteur1.Value = MaLigneIni Case 33 Me.TextBoxAuteur2.Value = MaLigneIni Case 34 Me.TextBoxAuteur3.Value = MaLigneIni Case 35 Me.TextBoxAuteur4.Value = MaLigneIni
Case 38 Me.TextBoxVerif1.Value = MaLigneIni Case 39 Me.TextBoxVerif2.Value = MaLigneIni Case 40 Me.TextBoxVerif3.Value = MaLigneIni Case 41 Me.TextBoxVerif4.Value = MaLigneIni End Select
i = i + 1 Loop Close #1
End If
Exit Sub
ErreurIniCartouche: MsgBox ("Erreur de lecture sur le fichier : " + FichierText) End