Gruppe
Extern
Problem
Wie kann ich mehrere Zeilen einer sequentiellen Textdatei durch Zellinhalte eines Excel-Arbeitsblattes ersetzen?
StandardModule: basMain
Sub CreateFile()
Dim rng As Range
Dim iFile As Integer, iRow As Integer, iCol As Integer
Dim sFile As String, sTxt As String
sFile = Application.Path & "\texttest.txt"
iFile = FreeFile
Open sFile For Output As iFile
For iRow = 1 To 10
For iCol = 1 To 5
sTxt = sTxt & "Zeile" & iRow & " - Spalte" & iCol & ","
Next iCol
sTxt = Left(sTxt, Len(sTxt) - 1)
Print #iFile, sTxt
sTxt = ""
Next iRow
Close
Workbooks.OpenText _
Filename:=sFile, _
DataType:=xlDelimited, _
tab:=False, _
semicolon:=False, _
comma:=True, _
Space:=False, _
other:=False
Columns.AutoFit
MsgBox "Weiter"
For Each rng In ThisWorkbook.Worksheets("Tabelle1") _
.Range("A1:E10").Cells
If Not IsEmpty(rng) Then
Range(rng.Address).Value = rng.Value
End If
Next rng
MsgBox "Weiter"
ActiveWorkbook.Close savechanges:=False
Kill sFile
End Sub