Using this:
Private Sub Create_CSV()
Dim content As String
Dim Rng As Range
Set Rng = Range("A12:AS30")
Dim Path As String
Dim FileName1 As String
Dim FileName2 As String
Dim FileName3 As String
Dim sWB As Workbook, _
sWS As Worksheet
Dim dWB As Workbook, _
dWS As Worksheet
Path = "PATH\"
FileName1 = Range("A16")
FileName2 = Range("B16")
Set sWB = ActiveWorkbook
Set sWS = sWB.ActiveSheet
Set dWB = Workbooks.Add
Set dWS = dWB.Sheets(1)
sWS.Range("A12:AS30").Copy
dWS.Range("A1").PasteSpecial xlPasteValues
dWB.SaveAs filename:=Path & FileName1 & "_" & FileName2 & ".csv", FileFormat:=xlCSV, Local:=True, CreateBackup:=False
dWB.Close False
End Sub
I have a file with formulas that collects data from other tabs in the workbook, and some of the fields contain dates, those fields are formatted correctly.
But when saving to CSV the date format (YYYY-MM-DD) is lost and it saves it as a number (43983) instead.
Private Sub Create_CSV()
Dim content As String
Dim Rng As Range
Set Rng = Range("A12:AS30")
Dim Path As String
Dim FileName1 As String
Dim FileName2 As String
Dim FileName3 As String
Dim sWB As Workbook, _
sWS As Worksheet
Dim dWB As Workbook, _
dWS As Worksheet
Path = "PATH\"
FileName1 = Range("A16")
FileName2 = Range("B16")
Set sWB = ActiveWorkbook
Set sWS = sWB.ActiveSheet
Set dWB = Workbooks.Add
Set dWS = dWB.Sheets(1)
sWS.Range("A12:AS30").Copy
dWS.Range("A1").PasteSpecial xlPasteValues
dWB.SaveAs filename:=Path & FileName1 & "_" & FileName2 & ".csv", FileFormat:=xlCSV, Local:=True, CreateBackup:=False
dWB.Close False
End Sub
I have a file with formulas that collects data from other tabs in the workbook, and some of the fields contain dates, those fields are formatted correctly.
But when saving to CSV the date format (YYYY-MM-DD) is lost and it saves it as a number (43983) instead.