|
发表于 2013-6-30 21:17
|
显示全部楼层
本楼为最佳答案
- Sub ReadCSV()
- Dim arr
- Dim strCSV As String
- On Error GoTo ErrorHandler
- strCSV = Left(ThisWorkbook.FullName, InStrRev(ThisWorkbook.FullName, ".") - 1) & ".csv"
- If Len(Dir(strCSV)) = 0 Then
- MsgBox "当前工作簿目录下没有 " & strCSV, vbCritical + vbOKOnly
- Exit Sub
- End If
- With Application
- .ScreenUpdating = False
- .DisplayAlerts = False
- .EnableEvents = False
- .Calculation = xlCalculationManual
- End With
- Workbooks.Open Filename:=strCSV, ReadOnly:=True
- arr = ActiveSheet.UsedRange.Value
- ActiveWorkbook.Close False
-
- If IsArray(arr) Then
- With Worksheets("read")
- .Cells(Rows.Count, 1).End(xlUp).Offset(2).Resize(UBound(arr), UBound(arr, 2)).Value = arr
- End With
- MsgBox "复制完成"
- End If
- With Application
- .ScreenUpdating = True
- .DisplayAlerts = True
- .EnableEvents = True
- .Calculation = xlCalculationAutomatic
- End With
- Exit Sub
- ErrorHandler:
- With Application
- .ScreenUpdating = True
- .DisplayAlerts = True
- .EnableEvents = True
- .Calculation = xlCalculationAutomatic
- End With
- MsgBox Err.Number & vbCrLf & _
- Err.Description
- End Sub
复制代码 |
|