I have a problem working with some worksheets within a workbook from a 3rd party website source.
- the spreadsheet is available at the 3rd party source website
- the worksheet I am having problems with is the
EC
worksheet in theall-euro-data-2009-2010.xls
in that zipfile
It's a list of football match data.
Manual Save as CSV
Now when this "EC" spreadsheet is in focus and I go to SAVE AS and choose .CSV, then spreadsheet is saved as a CSV and the data is perfect. ie the dates in column "B" and they are as they should be in DD/MM/YYYY format.
EG , taken from last row of the EC worksheet EC,24/04/2010,Tamworth,Ebbsfleet
This is correct, if I go to the menu and choose to "SAVE AS" and chose CSV and accept all the prompts to keep it in CSV format blah blah the CSV file is save as EC,24/04/2010,Tamworth,Ebbsfleet
This is correct as the dates are in UK dd/mm/yyyy
VBA Save as CSV
Now to make things a hell of a lot easier for myself as I need to save each worksheet off as a csv file so I am using the VBA code below to auto save each worksheet in the current directory named as worksheetname.csv ( eg EC.csv) each time the workbook is closed however this is changes the dates in column B to Americam format MM/DD/YYYY.
However using VBA to save as a CSV the data ends up like EC,4/24/2010,Tamworth,Ebbsfleet
Notice the change from UK dd/mm/yyyy to now the American format mm/dd/yyyy
How can I make the change in the VBA to keep the dates in the format shown in the actual spreadsheet ie dd/mm/yyyy when saving in vba to CSV?
I need this CSV option to work in VBA as these and many other similar spreadsheets are saved as CSV files for importation EVERY DAY.
My settings
I am using Excel 2007, on a Win 7 (64bit) PC here in the UK.
I have also tried add the Local:=True to the ws.SaveAs but this made no difference. ie the dates still saved as EC,4/24/2010,Tamworth,Ebbsfleet when saving from VBA
Thanks
Option Explicit
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Alerts_Suppress
ThisWorkbook.Save
Save_All_WorkSheets_As_CSV
Alerts_Enable
ActiveWorkbook.Close False
Application.Quit
End Sub
Sub Save_All_WorkSheets_As_CSV()
Dim Name As String
Dim Current_Directory As String
Dim ws As Worksheet
Dim wb As Workbook
Set wb = ActiveWorkbook
Dim i As Integer
i = 0
Current_Directory = ActiveWorkbook.Path & "\"
For Each ws In wb.Worksheets
Name = Current_Directory & LCase(ws.Name) + ".csv"
ws.SaveAs Name, xlCSV
i = i + 1
Next
End Sub
Sub Alerts_Suppress()
Application.DisplayAlerts = False
End Sub
Sub Alerts_Enable()
Application.DisplayAlerts = True
End Sub