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"
If
Right(strPath, 1) <>
"\" Then strPath = strPath & "
\"
strDivider =
";"
lngStartRow = 4
lngStartCol = 3
With
Sheets(
"Speichern der Datei1"
)
lngLastRow = Application.Max(lngStartRow, .Cells(.Rows.Count, 4).
End
(xlUp).Row)
lngLastCol = Application.Max(lngStartCol, .Cells(lngStartRow, .Columns.Count).
End
(xlToLeft).Column)
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.
<a href=
"http://praxistipps.chip.de/excel-button-einfuegen-so-gehts_39097"
style=
"background-color: transparent; box-sizing: border-box; color: rgb(51, 153, 243); font-family: "Open Sans","Helvetica Neue",Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"
>http://praxistipps.chip.de/excel-button-einfuegen-so-gehts_39097</a><span style=
"display: inline !important; float: none; background-color: transparent; color: rgb(102, 102, 102); font-family: "Open Sans","Helvetica Neue",Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"
> </span>
--------------------------------------------------------------
Falls das Trennzeichen
","
in der .txt Datei durch ein Zeilenubruch ersetzt werden soll,
dann den Befehl
<span style=
"display: inline !important; float: none; background-color: transparent; color: rgb(34, 34, 34); font-family: Arial,Verdana,sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: pre; word-spacing: 0px;"
>strDivider =
";"
</span>
ersetzten in
<span style=
"display: inline !important; float: none; background-color: rgb(248, 248, 255); color: rgb(0, 0, 0); font-family: courier new; font-size: 12px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: pre; word-spacing: 0px;"
>strDivider = vbCrLf</span>
Alles kann auch hier:
nocheinmal nachgelesen werden.
Danke nochmal an Sepp, der mir dabei sehr weitergeholfen hat.
Viele Grüße
Robert