Hi all,
I am using the below VBA to export a single sheet as a new CSV.
In the source file the date is shown as DD-MM-YYYY however when using the below it changes in the CSV file to MM-DD-YYYY?
If I don't use the VBA and copy the tab and save as CSV manually it does not do this so I can only assume I am missing something from the VBA?
Can anyone advise?
Also column A in the source data is in format of 5 digits with the first digit always as a "0" EG "01234" and the CSV file removes the leading "0" is there a way to stop this?
Sub saveExpressToCSV()
Dim myCSVFileName As String
Dim tempWB As Workbook
Application.DisplayAlerts = False
On Error GoTo err
myCSVFileName = ThisWorkbook.Path & "" & "Matrix-Express-" & VBA.Format(VBA.Now, "dd-MMM-yyyy hh-mm") & ".csv"
ThisWorkbook.Sheets("PriceRuleDaysExport").Activate
ActiveSheet.Copy
Set tempWB = ActiveWorkbook
With tempWB
.SaveAs Filename:=myCSVFileName, FileFormat:=xlCSV, CreateBackup:=False
.Close
End With
err:
Application.DisplayAlerts = True
Call Return_Express
End Sub
I am using the below VBA to export a single sheet as a new CSV.
In the source file the date is shown as DD-MM-YYYY however when using the below it changes in the CSV file to MM-DD-YYYY?
If I don't use the VBA and copy the tab and save as CSV manually it does not do this so I can only assume I am missing something from the VBA?
Can anyone advise?
Also column A in the source data is in format of 5 digits with the first digit always as a "0" EG "01234" and the CSV file removes the leading "0" is there a way to stop this?
Sub saveExpressToCSV()
Dim myCSVFileName As String
Dim tempWB As Workbook
Application.DisplayAlerts = False
On Error GoTo err
myCSVFileName = ThisWorkbook.Path & "" & "Matrix-Express-" & VBA.Format(VBA.Now, "dd-MMM-yyyy hh-mm") & ".csv"
ThisWorkbook.Sheets("PriceRuleDaysExport").Activate
ActiveSheet.Copy
Set tempWB = ActiveWorkbook
With tempWB
.SaveAs Filename:=myCSVFileName, FileFormat:=xlCSV, CreateBackup:=False
.Close
End With
err:
Application.DisplayAlerts = True
Call Return_Express
End Sub