简体   繁体   English

Excel VBA复制日期错误的数据

[英]Excel VBA Copying data with date error

Hi recently i have generated a csv data file using Foxpro 7.0. 嗨,最近我已经使用Foxpro 7.0生成了一个csv数据文件。 So I were going to use VBA to copy the data from A.csv to the reporting excel file B in the format of xlsm. 因此,我将使用VBA以xlsm格式将数据从A.csv复制到报表excel文件B中。

Workbooks("A")
Range("A2:AB300000").Copy
Workbooks("B").Activate
Sheets("C").Select
Range("B6").Select
ActiveSheet.Paste
Workbooks("A").Close 

and there are multiples files for me to copy. 而且有多个文件可供我复制。 My problem is I got different type of results in the date column, which contains randomly generated US/UK date with either general or date format. 我的问题是,日期列中有不同类型的结果,其中包含随机生成的常规格式的美国/英国日期或日期格式。 Please help and thanks in advance! 请帮助并提前致谢!

I use this code. 我使用此代码。

Sub TransToXLSFromCSV()
Dim vFile As Variant
Dim vDB
Dim fn As String
Dim strPath As String
Dim i As Long
Dim Wb As Workbook
    strPath = ThisWorkbook.Path
    vFile = Application.GetOpenFilename("Csv Files *.csv,*.csv;*.csv", _
      Title:="Select the Csv Files!", MultiSelect:=True)
    If TypeName(vFile) = "Boolean" Then Exit Sub
    Application.ScreenUpdating = False

    For i = 1 To UBound(vFile)
        fn = Dir(vFile(i))
        fn = Left(fn, Len(fn) - 4)

         Set Wb = Workbooks.Open(Filename:=vFile(i), Format:=2)
         vDB = Wb.ActiveSheet.UsedRange
         Wb.Close
         Set Wb = Workbooks.Add
         With Wb
            .ActiveSheet.Range("a1").Resize(UBound(vDB, 1), UBound(vDB, 2)) = vDB
            .SaveAs Filename:=strPath & "\" & fn & ".xlsx"
            .Close (0)
         End With
    Next i
    Application.ScreenUpdating = True
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM