Sub ExportToDatanorm4()
Dim ws As Worksheet
Dim filePath As String
Dim fileNum As Integer
Dim rowNum As Long
Dim dataLine As String
' Arbeitsblatt festlegen
Set ws = ThisWorkbook.Sheets("Tabelle1")
' Pfad für die Datanorm-Datei
filePath = Application.GetSaveAsFilename("Datanorm4.txt", "Textdateien (*.txt), *.txt")
If filePath = "False" Then Exit Sub
' Datei öffnen
fileNum = FreeFile
Open filePath For Output As #fileNum
' Schleife durch alle Datenzeilen
rowNum = 2 ' Annahme: Erste Zeile ist die Kopfzeile
Do While ws.Cells(rowNum, 1).Value <> ""
' Beispiel für eine Datanorm-Datensatzzeile (Typ 2 - Artikeldaten)
dataLine = _
"2|" & _
Format(ws.Cells(rowNum, 1).Value, "000000") & "|" & _ ' Artikelnummer
ws.Cells(rowNum, 2).Value & "|" & _ ' Artikelbezeichnung
ws.Cells(rowNum, 3).Value & "|" & _ ' Preis
ws.Cells(rowNum, 4).Value ' Mengeneinheit
' Zeile in die Datei schreiben
Print #fileNum, dataLine
rowNum = rowNum + 1
Loop
' Datei schließen
Close #fileNum
MsgBox "Export abgeschlossen: " & filePath, vbInformation
End Sub