Gruppe
Extern
Problem
Zwei Dateien mit der gleichen Zeilenanzahl werden Zeile für Zeile miteinander verglichen. Die Zeilen der ersten Datei, die Unterschiede zur jeweiligen Zeile der zweiten Datei aufweisen, werden in eine dritte Datei geschrieben.
StandardModule: basMain
Sub Anlegen()
Dim iFile As Integer, iRow As Integer, iCol As Integer
Dim sFile As String
iFile = FreeFile
For iCol = 1 To 2
sFile = Application.Path & "\test" & iCol & ".txt"
Open sFile For Output As iFile
iRow = 1
Do Until IsEmpty(Cells(iRow, iCol))
Print #iFile, Cells(iRow, iCol).Value
iRow = iRow + 1
Loop
Close iFile
Next iCol
MsgBox "Die Testdateien wurden angelegt!"
End Sub
Sub Vergleich()
Dim iCounter As Integer, iFile As Integer
Dim sPath As String, txtA As String, txtB As String
sPath = Application.Path & "\"
iFile = FreeFile
Open sPath & "test1.txt" For Input As iFile
Open sPath & "test2.txt" For Input As iFile + 1
Open sPath & "test3.txt" For Output As iFile + 2
Do Until EOF(1)
iCounter = iCounter + 1
Line Input #iFile, txtA
Line Input #iFile + 1, txtB
If txtA <> txtB Then
Print #iFile + 2, txtA & " - " & txtB
End If
Loop
Close
sPath = sPath & "test3.txt"
Workbooks.OpenText _
Filename:=sPath, _
DataType:=xlDelimited, _
tab:=False, _
semicolon:=False, _
comma:=False, _
Space:=False, _
other:=False
Columns.AutoFit
MsgBox "Weiter"
ActiveWorkbook.Close savechanges:=False
Kill sPath
End Sub