With VBA (in Excel) I want to read serveral text files. These files allways have 2 lines. I want to sort and write new files,
where the first line of each text file is leading and must be on alphabeticaly order.
So I have:
testfile0001.txt -> line 1: "Thanks" and line 2 "100"
testfile0002.txt -> line 1: "Many" and line 2 "50"
And the result has to be:
testfile0001.txt -> line 1: "Many" and line 2 "50"
testfile0002.txt -> line 1: "Thanks" and line 2 "100"
to read the testfiles I have made this:
Dim line1(100000) As String
Dim line2(100000) As String
Dim tmp As String
Dim i As Integer
Dim b As Integer
files = "C:test"
.LookIn = files
.SearchSubFolders = False
.FileName = "testfile"
.MatchAllWordForms = True
.FileType = msoFileTypeAllFiles
If .Execute() > 0 Then aantal = .FoundFiles.Count
i = 1
For b = 1 To aantal
Open .FoundFiles(b) For Input As #1
Line Input #1, tmp
Line Input #1, tmp2
line1(i) = tmp
line2(i) = tmp2
i = i + 1
If you like these VB formatting tags please consider sponsoring the author in support of injured Royal Marines
This does read all the textfiles ok, but now I don't know how to sort them (line1) and to write them. (line1 and
line2) Anybody can help me with this?