您好我最近使用Foxpro 7.0生成了一个csv数据文件。所以我打算用VBA将数据从A.csv复制到报告的excel文件B,格式为xlsm。
Workbooks("A")
Range("A2:AB300000").Copy
Workbooks("B").Activate
Sheets("C").Select
Range("B6").Select
ActiveSheet.Paste
Workbooks("A").Close
并且有多个文件供我复制。 我的问题是我在日期列中得到了不同类型的结果,其中包含随机生成的美国/英国日期,包括常规或日期格式。 请提前帮助和感谢!
答案 0 :(得分:0)
我使用此代码。
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