Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function ParsefileAsTable(ByVal sNomFichier As String) As Variant
- Dim Chaine As String
- Dim Ar() As String
- Dim var As Variant
- Dim nblignes As Long
- Dim nbcol As Long
- Dim i As Long
- Dim iRow As Long, iCol As Long
- Dim NumFichier As Integer
- Dim Separateur As String * 1
- Separateur = ","
- With Application
- .ScreenUpdating = False
- .EnableEvents = False
- End With
- Close
- NumFichier = FreeFile
- iRow = 0
- Open sNomFichier For Input As #NumFichier
- Do While Not EOF(1)
- Line Input #NumFichier, Chaine
- nblignes = nblignes + 1
- Ar = Split(Chaine, Separateur)
- nbcol = UBound(Ar) + 1
- Loop
- Close #NumFichier
- ReDim var(1 To nblignes, 1 To nbcol)
- iRow = 0
- Open sNomFichier For Input As #NumFichier
- Do While Not EOF(NumFichier)
- iCol = 1: iRow = iRow + 1
- Line Input #NumFichier, Chaine
- Ar = Split(Chaine, Separateur)
- For i = LBound(Ar) To UBound(Ar)
- If Not iCol > nbcol Then
- var(iRow, iCol) = Ar(i)
- iCol = iCol + 1
- End If
- Next
- Loop
- Close #NumFichier
- With Application
- .ScreenUpdating = True
- .EnableEvents = True
- End With
- ParsefileAsTable = var
- End Function
- Function ParsefileAsTable(ByVal sNomFichier As String) As Variant
- ParsefileAsTable = var
- Dim var as Variant
- var = ParseFileAsTable("C:mon_fichier.txt")
- Range("A1").Resize(UBound(var, 1), UBound(var, 2)).Value = _
- var
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement