Option
Explicit
Private
Declare
PtrSafe
Function
MakeSureDirectoryPathExists
Lib
"imagehlp.dll"
(
ByVal
Pfad
As
String
)
As
Long
Sub
SaveAsCSV()
Dim
DstPfad
As
String
Dim
DstFileName
As
String
DstPfad =
"C:\Daten\" & Format$(Date, "
YYYY\\MMMM\\")
DstFileName = DstPfad & Format(Now,
"YYYYMMDD"
) &
".csv"
If
Not
CBool
(MakeSureDirectoryPathExists(DstPfad))
Then
Call
MsgBox(
"Ziel-Verzeichnis konnte nicht erstellt werden."
, vbExclamation)
Exit
Sub
End
If
Dim
QNr
As
Long
QNr = FreeFile()
Open DstFileName
For
Output
As
#QNr
Close #QNr
End
Sub