如何在excel中保留csv文件的日期格式

时间:2015-03-31 13:09:31

标签: excel-vba csv vba excel

csv文件的dateformat是“yyyy-mm-dd”在excel中打开时显示dd / mm / yyyy 我想在excel中显示原始格式

感谢

1 个答案:

答案 0 :(得分:1)

从以下数据开始:

enter image description here

尝试运行像:

这样的宏
Sub GetDatesFromCSV()

    With ActiveSheet.QueryTables.Add(Connection:= _
        "TEXT;C:\Users\JamesRavenswood\Desktop\temp.csv", Destination:=Range("$A$1"))
        .Name = "temp"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 437
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = True
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = False
        .TextFileSpaceDelimiter = False
        .TextFileColumnDataTypes = Array(5)
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
    End With

    Range("A:A").NumberFormat = "yyy-mm-dd"
End Sub