Hi folks,
Can anyone edit the snippet below to add a datestamp to the cvs filename in the format "yyyy-mm-dd hh-mm-ss"?
Many thanks in advance!
Can anyone edit the snippet below to add a datestamp to the cvs filename in the format "yyyy-mm-dd hh-mm-ss"?
Many thanks in advance!
Code:
Sub saveTableToCSV()
Dim tbl As ListObject
Dim csvFilePath As String
Dim fNum As Integer
Dim tblArr
Dim rowArr
Dim csvVal
Set tbl = Worksheets("DD_Load_Template").ListObjects("qry_DD_Template_Merge")
csvFilePath = "S:\Temp\DDs\DD_CSV.csv"
tblArr = tbl.DataBodyRange.Value
fNum = FreeFile()
Open csvFilePath For Output As [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=fNum]#fNum[/URL]
For i = 1 To UBound(tblArr)
rowArr = Application.Index(tblArr, i, 0)
csvVal = VBA.Join(rowArr, ",")
Print [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] , csvVal
Next
Close [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=fNum]#fNum[/URL]
Set tblArr = Nothing
Set rowArr = Nothing
Set csvVal = Nothing
End Sub