Gruppe
Extern
Problem
Wie kann ich einen Excel-Bereich mit einer festen Feldlänge für alle Spalten in eine Textdatei exportieren?
StandardModule: basMain
Sub Export()
Dim rng As Range
Dim iLength As Integer, iFile As Integer
Dim iRow As Integer, iCol As Integer
Dim sFile As String, sTxt As String, sText As String
Set rng = Range("A1").CurrentRegion
iLength = 20
iFile = FreeFile
sFile = Application.Path & "\testtext.txt"
Open sFile For Output As iFile
For iRow = 1 To rng.Rows.Count
For iCol = 1 To rng.Columns.Count
sTxt = Cells(iRow, iCol).Text
sText = sText & sTxt & String(20 - Len(sTxt), " ")
Next iCol
Print #iFile, sText
sText = ""
Next iRow
Close
Workbooks.OpenText _
Filename:=sFile, _
DataType:=xlFixedWidth, _
tab:=False, _
semicolon:=False, _
comma:=False, _
Space:=False, _
other:=False, _
FieldInfo:=Array(Array(0, 1), Array(20, 1), _
Array(40, 1), Array(60, 1))
MsgBox "Weiter"
ActiveWorkbook.Close savechanges:=False
Kill sFile
End Sub
StandardModule: Modul1
Sub Makro1()
Makro1 Makro
Makro am 19.09.2002 von Hans W. Herber aufgezeichnet
Workbooks.OpenText Filename:="C:\Temp\test.txt", Origin:=xlWindows, _
StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 1), Array(3, _
1), Array(22, 1), Array(29, 1))
End Sub