另存为 CSV 文件时日期格式发生变化

问题描述 投票:0回答:1

我有表格格式的数据(不是ListObject):

身份证 |第 2 栏 |日期(日/月/年)| ...其他专栏 | C2(最后一栏)

还有这段代码

Sub exportCSV(path_name As String)
    
    Dim wb As Workbook, newWb As Workbook
    Dim dataSheet As Worksheet
    Dim mailTo As String, mailCC As String, mailBCC As String, mailContent As String
    Dim outlookApp As Object, outlookMail As Object, outlookSign As Object
    Dim newFileName As String
    Dim CRMid As String
    
    Set wb = ThisWorkbook
    Set Admin = wb.Sheets("Administration")
    Set dataSheet = wb.Sheets("CRM template")
    dataSheet.PivotTables("PivotTable2").ClearAllFilters
    dataSheet.PivotTables("PivotTable2").RefreshTable
    DoEvents
    CRMid = getLetterOfColumn("Id", "CRM template")
    
    ' Copy the desired range
    Dim lastRow As Long
    lastRow = dataSheet.Cells(dataSheet.Rows.Count, "B").End(xlUp).row
    Dim lastColumn As String
    lastColumn = getLetterOfColumn("C2", "CRM template")
    
    'retirage
    
    dataSheet.Range(CRMid & "6:" & lastColumn & lastRow).Formula = dataSheet.Range(CRMid & "6:" & lastColumn & "6").Formula
    
    
    'Copy
    dataSheet.Range(CRMid & "5:" & lastColumn & lastRow).Copy
    
    
    Set newWb = Workbooks.Add
    
    With newWb.Sheets(1).Range("A1")
        .PasteSpecial Paste:=xlPasteValues ' Paste values
        .PasteSpecial Paste:=xlPasteFormats ' Paste formats
        '.PasteSpecial Paste:=xlPasteColumnWidths ' Paste column widths
    End With
    
    ' Name new workbook
    Dim name_no_extension As String
    name_no_extension = Replace(wb.Name, ".xlsm", "")
    newFileName = path_name & "\" & "TRACKER_" & name_no_extension & ".csv"
    
     ' Save File as CSV UTF-8
    Application.DisplayAlerts = False
    newWb.SaveAs Filename:=newFileName, FileFormat:=xlCSVUTF8
    newWb.Close SaveChanges:=False
    Application.DisplayAlerts = True

end sub

使用该函数时,我确实获取了 CSV 格式的数据,但问题是现在的

Date
列格式而不是
m/d/yyyy
我发现类似的问题建议在保存文件时使用

dd/mm/yy

,但是当我使用时出现的问题是我不再获得csv格式的文件,我只是获得正常的表格格式。换句话说,该参数破坏了 csv 格式,并且 csv 必须采用 UTF-8 编码。

我在法国,我的笔记本电脑的区域设置是正确的,并且具有 

local:=True

分隔和

;
格式。
CSV 文件列用 

dd/mm/yyyy

分隔,而不是

,
    

excel vba export-to-csv
1个回答
0
投票

类似的东西

;

	
© www.soinside.com 2019 - 2024. All rights reserved.