ich habe folgendes Problem:
Ich habe in einer Datei mit mehreren Sheets ein Tabellenblatt, das ich per VBA als CSV-Datei speichern möchte. Im Tabellenblatt habe ich in 2 Spalten Uhrzeiten z.B. 20:15 hinterlegt. Wenn ich das Tabellenblatt als CSV speichere, macht das Makro aus der Uhrzeit den entsprechenden Zahlenwert. Wenn ich das manuell mache, also das Blatt in eine neue Datei kopiere und als CSV abspeichere, funktioniert es.
Außerdem habe ich hier noch das Problem, wenn ein Formelergebnis in einer Zelle "NULL" ergibt, wird in der CSV-Datei per Makro eine "0" eingetragen, manuell, also das Blatt in eine neue Datei kopieren und als CSV abspeichern,wird hier wie ich es brauche ein "Blank" gesetzt.
Könnt ihr mir hier weiterhelfen?
Gruß Ralf
Hier der Code
Sub copy_lbase_csv()
Dim strSep As String, strDat As String, _
iCol As Byte, iRow As Integer, _
iR As Integer, iC As Byte, strTxt As String, _
strMldg As String
iRow = ActiveSheet.UsedRange.Rows.Count
iCol = ActiveSheet.UsedRange.Columns.Count
strSep = Chr(59)
DateiName:
'strDat = InputBox("Dateiname?", "DateiName", ThisWorkbook.Path & "\")
strDat = "G:\Dokumente\JITEX-I\T4F\Fahrplan Stand " & Format(Date, "DDMMYYYY") & " _
Produktion.csv"
If strDat = "" Then Exit Sub
If InStr(strDat, ":\") = 0 Then
strDat = "G:\Dokumente\JITEX-I\T4F\Fahrplan Stand " & Format(Date, "DDMMYYYY") & " _
Produktion.csv" & strDat
End If
If Dir(strDat) "" Then
strMldg = MsgBox("Datei bereits vorhanden. Überschreiben?", vbYesNo)
If strMldg = vbNo Then GoTo DateiName
End If
On Error GoTo DateiFehler
Open strDat For Output As #1
For iR = 1 To iRow
strTxt = ""
For iC = 1 To iCol
strTxt = strTxt & Cells(iR, iC) & strSep
Next iC
strTxt = Left(strTxt, Len(strTxt) - 1)
Print #1, strTxt
Next iR
Close #1
MsgBox ("Die Datei " & strDat & " wurde angelegt.")
Exit Sub
DateiFehler:
MsgBox ("Fehler in Dateinamen!")
Resume DateiName
End Sub