I use amacro
to convert txt files into xls
but I have the problem that the fields with dates are not converting in the right format. For example I have the date 4/11/2014
(dd/mm/yyyy)
and when the file is converted into xls
, I have the date shown like this :11/4/2014.
How can I fix it?
code:
Public Sub Read_TXT()
Dim Dir_p As String, File_to_Open As String
Dir_p = ActiveWorkbook.path
File_to_Open = Dir(Dir_p & "\")
While File_to_Open <> ""
If InStr(1, Right(File_to_Open, 3), "txt", vbTextCompare) <> 0 Then
Workbooks.OpenText Filename:=Dir_p & "\" & File_to_Open, _
Origin:=xlWindows, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
Comma:=False, Space:=False, Other:=False, _
TrailingMinusNumbers:=True
ActiveWorkbook.SaveAs Filename:=Dir_p & "\" & Left(File_to_Open, Len(File_to_Open) - 3) & "xlsx" _
, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
ActiveWorkbook.Close
End If
File_to_Open = Dir
Wend
End Sub