AW: Mehrere Dateien in eine Tabelle
18.07.2008 12:47:38
Tino
Hallo,
hier mal ein Beispiel, die Excel- Datei befindet sich im Ordner der Textdateien.
Zwischen jeder Datei wird eine Leerzeile eingefügt.
Option Explicit
Dim lngRow As Long
Sub TXT_In_Excel()
Dim FName As String
Dim strPfad As String
With Application
.ScreenUpdating = False
.DisplayAlerts = False
Cells.ClearContents
lngRow = 0
strPfad = _
IIf(Right$(ThisWorkbook.Path, 1) = "\", _
ThisWorkbook.Path & "", _
ThisWorkbook.Path & "\")
FName = Dir(strPfad & "*.txt") 'Pfad angeben
While FName ""
ZeileLesen (strPfad & FName)
lngRow = lngRow + 1
FName = Dir()
Wend
.ScreenUpdating = False
.DisplayAlerts = False
End With
End Sub
Public Function ZeileLesen(DateiPfad As String)
Dim DateiNr As Long
Dim strZeile As String
DateiNr = FreeFile
Open DateiPfad For Input As #DateiNr
Do Until EOF(DateiNr)
Line Input #DateiNr, strZeile
lngRow = lngRow + 1
Cells(lngRow, 1) = strZeile
Cells(lngRow, 1).TextToColumns Destination:=Cells(lngRow, 1), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False
Loop
Close #DateiNr
End Function
Gruß Tino
www.VBA-Excel.de