Sub import()
'auteur macro d'origine: jindon
Dim myDir$, fn$, txt$, sepa$, a(), n As Long, i As Long, ff As Integer
sepa = ";"
myDir = "C:\TEMP\"
fn = Dir(myDir & "*.txt")
Do While fn <> ""
ff = FreeFile
Open myDir & fn For Input As #ff
Do While Not EOF(ff)
Line Input #ff, txt
n = n + 1: ReDim Preserve a(1 To n)
a(n) = Split(txt, sepa)
Loop
Close #ff
fn = Dir()
Loop
With ThisWorkbook.Sheets(1).[a1]
For i = 1 To n
.Offset(i - 1).Resize(, UBound(a(i)) + 1).Value = a(i)
Next
End With
End Sub
Sub test_import()
Dim chemin$, fichier$
chemin = "C:\TEMP\"
fichier = ThisWorkbook.Sheets(1).[a1].Text
Workbooks.OpenText chemin & fichier
end sub
Option Explicit
Sub SelFichier()
Dim Fichier As Variant
ChDir ThisWorkbook.Path
Fichier = Application.GetOpenFilename("Texte,*.txt", 1, _
"Sélectionner un fichier", , MultiSelect:=False)
If TypeName(Fichier) = "Boolean" Then Exit Sub
DoEvents
Application.ScreenUpdating = False
Workbooks.OpenText Fichier
Application.ScreenUpdating = True
End Sub
Sub ImportTXTbis()
'auteur macro originale: Andy Pope
Dim strPath$, strFile$, i As Long
strPath = [B1].Text
With ThisWorkbook.Sheets(1)
For i = 4 To .[A4].End(xlDown).Row
strFile = .Cells(i, 1).Text
Application.ScreenUpdating = False
With ActiveWorkbook.Worksheets.Add
ActiveSheet.Move after:=Sheets(ActiveWorkbook.Worksheets.Count)
With .QueryTables.Add(Connection:="TEXT;" & strPath & strFile, _
Destination:=.Range("A1"))
.Parent.Name = Replace(strFile, ".txt", "")
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileSemicolonDelimiter = True
.TextFileColumnDataTypes = Array(1)
.Refresh BackgroundQuery:=False
End With
End With
Next i
End With
Application.ScreenUpdating = False
End Sub
Sub ImportTXT_B()
'auteur macro originale: Andy Pope
Dim strPath$, strFile$, i As Long
strPath = "C:\temp\"
With ThisWorkbook.Sheets(1)
For i = 1 To .[A65536].End(xlUp).Row
strFile = .Cells(i, 1).Text
Application.ScreenUpdating = False
With ActiveWorkbook.Worksheets("IMPORTATION")
With .QueryTables.Add(Connection:="TEXT;" & strPath & strFile, _
Destination:=.[A65536].End(xlUp).Offset(1))
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileSemicolonDelimiter = True
.TextFileColumnDataTypes = Array(1)
.Refresh BackgroundQuery:=False
End With
.[A1].CurrentRegion.Columns.AutoFit
End With
Next i
End With
Application.ScreenUpdating = False
End Sub
Sub import_der()
'auteur macro d'origine: jindon
Dim myDir$, fn$, txt$, sepa$, a()
Dim n As Long, i As Long, j As Long, ff As Integer
sepa = ";": myDir = "C:\TEMP\"
With ThisWorkbook.Sheets(1)
For j = 1 To .[A65536].End(xlUp).Row
ff = FreeFile
Open myDir & .Cells(j, 1).Text For Input As #ff
Do While Not EOF(ff)
Line Input #ff, txt
n = n + 1: ReDim Preserve a(1 To n)
a(n) = Split(txt, sepa)
Loop
Close #ff
Next j
With ThisWorkbook.Sheets(2).[a1]
For i = 1 To n
.Offset(i - 1).Resize(, UBound(a(i)) + 1).Value = a(i)
Next
End With
End With
End Sub
Sub importAvec_AssistantTEXTpourFormat()
Dim a As Workbook, b As Workbook
Dim chemin$: chemin = "C:\TEMP\": Set a = ThisWorkbook
Dim i As Long
Application.ScreenUpdating = False
With a
With .Sheets(1)
For i = 1 To .[A65536].End(xlUp).Row
Workbooks.OpenText Filename:=.Cells(i, 1).Text, Origin:=xlWindows, _
StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=True, Comma:=False _
, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 4), Array(2, 2), _
Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1), Array(8, 1), Array(9, 1), _
Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1), Array(14, 1), Array(15, 1), Array( _
16, 1), Array(17, 1))
Set b = ActiveWorkbook
b.ActiveSheet.UsedRange.Copy a.Sheets(2).[A65536].End(xlUp).Offset(1)
b.Close True
Next
End With
With .Sheets(2)
.Rows("1:1").EntireRow.Delete
With .[A1].CurrentRegion
.Columns.AutoFit
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
End With
End With
End With
Application.ScreenUpdating = True
End Sub