AW: Aus Textdatei zum Excel
13.07.2009 12:37:53
Christian
Hallo Stan,
du könntest z.B. mit grep aus Unixutils du Zeilen aus einer Datei sehr einfach filtern und in ein neues File schreiben. Das geht natürlich auch mit VBA, ist aber entsprechend langsamer. Hier ein Bsp.
Gruß
Christian
Option Explicit
Sub TestIt()
Const strIN As String = "D:\Quelldatei.csv"
Const strOUT As String = "D:\Zieldatei.csv"
Const strFILTER As String = "1234567689"
Call Grep(strIN, strOUT, strFILTER)
End Sub
Sub Grep(strInFile As String, strOutFile As String, strSrch As String)
Dim intFile As Integer, k As Long, strLine As String
Dim col As New Collection
intFile = FreeFile()
Open strInFile For Input As #intFile
Do While Not EOF(intFile)
Line Input #intFile, strLine
If InStr(strLine, strSrch) Then col.Add strLine
Loop
Close #intFile
intFile = FreeFile()
Open strOutFile For Output As #intFile
For k = 1 To col.Count
Print #intFile, col(k)
Next
Close #intFile
End Sub