ein paar Ergänzungen + Korrekturen
08.05.2009 08:57:53
Erich
Hi Rolf,
hier beide Varianten - nicht bildschön, aber wohl lauffähig:
Option Explicit
Sub Read_Extern_file_in_Steps2()
Dim Text1 As String
Dim TxtLines As Long, i As Long, readStep As Long, zz As Long
Dim TextArr As Variant
Const strDatei = "\txttest.txt"
readStep = 20
Close #1
Open ThisWorkbook.Path & strDatei For Input As #1
TxtLines = 0
Do While Not EOF(1) ' Schleife bis Dateiende.
Input #1, Text1 ' Hilfsvariable zum einlesen verwenden
TxtLines = TxtLines + 1
Loop
Close #1
'Erneutes Öffnen um zum Dateianfang zu kommen
Open ThisWorkbook.Path & strDatei For Input As #1 ' Datei zum Einlesen öffnen.
ReDim TextArr(TxtLines)
Do While Not EOF(1) ' Schleife bis Dateiende.
Input #1, Text1
TextArr(i) = Text1 ' Hilfsvariable zum einlesen verwenden
i = i + 1
Loop
Close #1
Cells(1, 1) = TextArr(0)
zz = 1
For i = 1 To TxtLines Step readStep
zz = zz + 1
Cells(zz, 1) = TextArr(i)
Next i
End Sub
Sub tttt2()
Dim i As Integer, n As Long, strTmp As String, arrDaten(), k As Integer
Dim iFile As Integer
Const strDatei = "\txttest.txt"
iFile = FreeFile
Open ThisWorkbook.Path & strDatei For Input As iFile
Do While Not EOF(iFile)
Line Input #iFile, strTmp
n = n + 1
Loop
Close #iFile
ReDim arrDaten(1 To n, 1 To 7)
n = 0
Open ThisWorkbook.Path & strDatei For Input As iFile
Line Input #iFile, strTmp
n = n + 1
For i = 1 To 7
arrDaten(n, i) = Split(strTmp, vbTab)(i - 1)
Next
Do While Not EOF(iFile)
Line Input #iFile, strTmp
n = n + 1
For i = 1 To 7
arrDaten(n, i) = Split(strTmp, vbTab)(i - 1)
Next
For k = 1 To 19 'Zeilen überspringen
If Not EOF(iFile) Then Line Input #iFile, strTmp
Next
Loop
Close #iFile
Sheets(1).Cells(1, 1).Resize(n, 7) = arrDaten
End Sub
Rückmeldung wäre nett! - Grüße von Erich aus Kamp-Lintfort