AW: CSV Export nicht richtig formatiert.
04.04.2016 13:21:54
fcs
Hallo Astra,
eine so spezielle Variante bei der bestimte Spalten mit Text immer in Anführungszeichen gesetzt werden kamm man nur per Makro lösen.
Gruß
Franz
Sub CSV_Spezial()
Dim wks As Worksheet
Dim strDateiCSV As String
Dim Zeile As Long, ZeileL As Long, Spalte As Long, SpalteL As Long
Dim FF As Integer
Dim strS As String 'Trenzeichen zwischen Datenfeldern
Dim strText As String, strTemp As String
strS = ","
'Dateiname CSV-DAtei
strDateiCSV = ThisWorkbook.Path & "\" & "productexport_" & Format(Time, "HHMMSS") & ".csv"
Set wks = ActiveSheet
FF = FreeFile
Open strDateiCSV For Output As FF
With wks
SpalteL = 24 'Anzahl DatenSpalten
ZeileL = .Cells(.Rows.Count, 1).End(xlUp).Row
Überschriftenzeile einlesen
Zeile = 1
strText = .Cells(1, 1).Text
For Spalte = 2 To SpalteL
strText = strText & "," & .Cells(Zeile, Spalte).Text
Next
Print #FF, strText
'restliche zeilen einlesen
For Zeile = 2 To ZeileL
strText = .Cells(Zeile, Spalte).Text 'Id
For Spalte = 2 To SpalteL
Select Case Spalte
Case 2
'Datum speziell formatiert (oder in Excel formatieren und als Text + Anfü _
hrungszeichen)
strText = strText & strS & """" & Format(.Cells(Zeile, Spalte).Value, _
"YYYY-MM-DD hh:mm:ss") & """"
Case 99
'Wert in Zelle (können mehr Zeichen sein als angezeigt.
strText = strText & strS & .Cells(Zeile, Spalte).Value 'Zahlenwerte
Case 8
strTemp = Format(.Cells(Zeile, Spalte).Value, "0.00")
strTemp = Replace(strTemp, ",", "X")
strTemp = Replace(strTemp, ".", ",")
strTemp = Replace(strTemp, "X", ".")
'Wert in Zelle is zahl der Deutsche Formatierung in Excel in US-Format umgesetzt _
werden
strText = strText & strS & strTemp
Case 6, 7, 9, 11, 12, 13 To 24
'Inhalte wie in Excel angezeigt
strText = strText & strS & .Cells(Zeile, Spalte).Text 'Inhalte wie angezeigt
Case 4, 5, 10
'Inhalte wie angezeigt + zusätzliche Anführungszeichen
strText = strText & strS & """" & .Cells(Zeile, Spalte).Text & """"
End Select
Next
Print #FF, strText
Next
End With
Close #FF
End Sub