|
Option Explicit
Option Compare Text
Sub test()
Dim ar, br, cr, i&, j&, k&, r&, vFile, Filter$, iColSize&
Application.DefaultFilePath = ThisWorkbook.Path & "\"
Filter = "Excel Files(*.xls*), * .xls* "
vFile = Application.GetOpenFilename(Filter, 3, "请选择文件", , False)
If vFile = False Then Exit Sub
If FileName(vFile) = ThisWorkbook.Name Then
MsgBox "不能选择与本工作簿相同文件名的工作簿!", vbCritical
Exit Sub
End If
Application.ScreenUpdating = False
ar = Array("1", "2", "3", "4")
ReDim br(1 To 10 ^ 4, 1 To 10 ^ 3)
With GetObject(vFile)
For i = 0 To UBound(ar)
cr = .Worksheets(ar(i)).UsedRange.Value
For k = 1 To UBound(cr)
r = r + 1
For j = 1 To UBound(cr, 2)
br(r, j) = cr(k, j)
Next j
Next k
If UBound(cr, 2) > iColSize Then iColSize = UBound(cr, 2)
Next i
.Close False
End With
Cells.Clear
[A1].Resize(r, iColSize) = br
Application.ScreenUpdating = True
Beep
End Sub
Function FileName(FullName As Variant) As String
Application.Volatile
FileName = Right(FullName, Len(FullName) - InStrRev(FullName, "\"))
End Function
|
评分
-
1
查看全部评分
-
|