Hier das Skript:
---------------------------------
Option Explicit
Sub ErstelleDateien()
Dim strPath As String, strText As String, strDivider As String, strFileName As String
Dim lngRow As Long, lngStartRow As Long, lngLastRow As Long
Dim lngCol As Long, lngStartCol As Long, lngLastCol As Long
Dim FF As Integer
strPath = "C:\Users\Rober\Desktop\Skriptcode" 'Zielpfad
If Right(strPath, 1) <> "\" Then strPath = strPath & "\"
strDivider = ";" 'Trennzeichen der Textdatei - Anpassen
lngStartRow = 4 'Erste Zeile mit Daten
lngStartCol = 3 'Erste Spalte (Dateiname)
With Sheets("Speichern der Datei1") 'Tabellenname - Anpassen
lngLastRow = Application.Max(lngStartRow, .Cells(.Rows.Count, 4).End(xlUp).Row) 'letzte Zeile
lngLastCol = Application.Max(lngStartCol, .Cells(lngStartRow, .Columns.Count).End(xlToLeft).Column) 'letzte Spalte
For lngRow = lngStartRow To lngLastRow
strFileName = strPath & .Cells(lngRow, lngStartCol) & ".txt"
strText = ""
For lngCol = lngStartCol + 1 To lngLastCol
strText = strText & .Cells(lngRow, lngCol) & strDivider
Next
strText = Left(strText, Len(strText) - Len(strDivider))
FF = FreeFile
Open strFileName For Output As #FF
Print #FF, strText
Close #FF
Next
End With
End Sub
--------------------------------------------------------------
Hier die Anleitung um das Skript mit einem Button zu starten.
http://praxistipps.chip.de/excel-button-einfuegen-so-gehts_39097
--------------------------------------------------------------
Falls das Trennzeichen "," in der .txt Datei durch ein Zeilenubruch ersetzt werden soll,
dann den Befehl
strDivider = ";"
ersetzten in
strDivider = vbCrLf
Alles kann auch hier:
http://www.herber.de/forum/archiv/1596to1600/t1597522.htm
nocheinmal nachgelesen werden.
Danke nochmal an Sepp, der mir dabei sehr weitergeholfen hat.
Viele Grüße
Robert
|