Gruppe
Extern
Problem
Wie kann ich einen Tabellenblattbereich unter Aussparung einer bestimmten Spalte als Textdatei mit einem Leerzeichen als Feldtrenner speichern?
StandardModule: basMain
Sub AlsTextSpeichern()
Dim rng As Range
Dim iFile As Integer, iRow As Integer, iCol As Integer
Dim sFile As String, sTxt As String, sText As String
Set rng = Range("A1").CurrentRegion
iFile = FreeFile
sFile = Application.Path & "\texttest.txt"
Open sFile For Output As iFile
For iRow = 1 To rng.Rows.Count
For iCol = 1 To rng.Columns.Count
Select Case iCol
Case 1, 2, 4
sTxt = sTxt & Cells(iRow, iCol).Text & ";"
Case 5
sTxt = sTxt & Cells(iRow, iCol).Text
End Select
Next iCol
Print #iFile, sTxt
sTxt = ""
Next iRow
Close
Workbooks.OpenText _
Filename:=sFile, _
DataType:=xlDelimited, _
tab:=False, _
semicolon:=True, _
comma:=False, _
Space:=False, _
other:=False
Columns.AutoFit
MsgBox "Weiter"
ActiveWorkbook.Close savechanges:=False
Kill sFile
End Sub