Gruppe
Extern
Problem
Aus dem in Zelle B1 genannten Verzeichnis sollen die Texte aus allen *.txt-Dateien in eine neue Arbeitsmappe eingelesen werden. Jede Textdatei besteht nur aus einer Zeile.
StandardModule: Modul1
Sub ImportTextFiles()
Dim iRow As Integer
Dim sPath As String, stxt As String
Application.ScreenUpdating = True
sPath = Range("B1").Value
Close
Workbooks.Add 1
With Application.FileSearch
.NewSearch
.Filename = "*.txt"
.LookIn = sPath
.Execute
On Error Resume Next
For iRow = 1 To .FoundFiles.Count
Open .FoundFiles(iRow) For Input As #1
Line Input #1, stxt
Cells(iRow, 1).Value = stxt
Close
Next iRow
End With
On Error GoTo 0
Columns.AutoFit
Application.ScreenUpdating = True
End Sub