VBA to Open CSV and Avoid Date Error

You can create a macro to open a CSV file. One problem you may face is that dates are treated as US dates. A simple change can fix this.

The code to open a CSV can look like this

Sub Open_CSV()
Dim strPath As String
strPath = "E:A4\Data\Data.csv"
Workbooks.Open Filename:=strPath
End Sub

Unfortunately VBA defaults to using the US date format mm/dd/yy when it opens a CSV file.

Only the US uses that date structure, everyone else uses the dd/mm/yy.

The solution is easy, you just add an option to the end of the Open statement to instruct Excel to use the local date format.

You add ,Local:=True to the end of the Open statement. The adjusted code for the above macro is shown below.

Sub Open_CSV()
Dim strPath As String
strPath = "E:A4\Data\Data.csv"
Workbooks.Open Filename:=strPath, Local:=True
End Sub


 


	

Please note: I reserve the right to delete comments that are offensive or off-topic.

Leave a Reply

Your email address will not be published. Required fields are marked *