Gruppe
Extern
Problem
Wie kann ich Zellinhalte korrigieren und dann spaltenabhängig mit unterschiedlichen Feldlängen in eine *.dat-Textdatei speichern?
StandardModule: basMain
Sub Export()
Dim rng As Range
Dim iRow As Integer, iCol As Integer, iFile As Integer
Dim iLen As Integer
Dim sFile As String, sTxt As String, sText As String
Set rng = Range("A1").CurrentRegion
sFile = Application.Path & "\texttest.txt"
iFile = FreeFile
Open sFile For Output As iFile
For iRow = 2 To rng.Rows.Count
For iCol = 1 To rng.Columns.Count
iLen = Cells(1, iCol).Value
sText = Cells(iRow, iCol).Text
If Len(sText) > iLen Then
sText = Left(sText, iLen)
Else
sText = sText & String(iLen - Len(sText), " ")
End If
sTxt = sTxt & sText & ","
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"
ActiveWorkbook.Close savechanges:=False
Kill sFile
End Sub