Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. Function ParsefileAsTable(ByVal sNomFichier As String) As Variant
  2. Dim Chaine As String
  3. Dim Ar() As String
  4. Dim var As Variant
  5. Dim nblignes As Long
  6. Dim nbcol As Long
  7. Dim i As Long
  8. Dim iRow As Long, iCol As Long
  9. Dim NumFichier As Integer
  10. Dim Separateur As String * 1
  11.  
  12. Separateur = ","
  13. With Application
  14. .ScreenUpdating = False
  15. .EnableEvents = False
  16. End With
  17.  
  18. Close
  19. NumFichier = FreeFile
  20.  
  21. iRow = 0
  22. Open sNomFichier For Input As #NumFichier
  23.  
  24. Do While Not EOF(1)
  25. Line Input #NumFichier, Chaine
  26. nblignes = nblignes + 1
  27. Ar = Split(Chaine, Separateur)
  28. nbcol = UBound(Ar) + 1
  29. Loop
  30. Close #NumFichier
  31.  
  32. ReDim var(1 To nblignes, 1 To nbcol)
  33.  
  34. iRow = 0
  35. Open sNomFichier For Input As #NumFichier
  36. Do While Not EOF(NumFichier)
  37. iCol = 1: iRow = iRow + 1
  38. Line Input #NumFichier, Chaine
  39. Ar = Split(Chaine, Separateur)
  40. For i = LBound(Ar) To UBound(Ar)
  41. If Not iCol > nbcol Then
  42. var(iRow, iCol) = Ar(i)
  43. iCol = iCol + 1
  44. End If
  45. Next
  46. Loop
  47. Close #NumFichier
  48.  
  49. With Application
  50. .ScreenUpdating = True
  51. .EnableEvents = True
  52. End With
  53.  
  54. ParsefileAsTable = var
  55.  
  56. End Function
  57.  
  58. Function ParsefileAsTable(ByVal sNomFichier As String) As Variant
  59.  
  60. ParsefileAsTable = var
  61.  
  62. Dim var as Variant
  63. var = ParseFileAsTable("C:mon_fichier.txt")
  64.  
  65. Range("A1").Resize(UBound(var, 1), UBound(var, 2)).Value = _
  66. var
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement