|
|
Sub pldrwb0531()
'汇总表.xls
'导入指定文件的数据
Dim myFs As FileSearch
Dim myPath As String, Filename$
Dim i As Long, n As Long
Dim Sht1 As Worksheet, sh As Worksheet
Dim aa, nm$, nm1$, m, arr, r1, col1%
Application.ScreenUpdating = False
Set Sht1 = ActiveSheet
Set myFs = Application.FileSearch
myPath = ThisWorkbook.Path
With myFs
.NewSearch
.LookIn = myPath
.FileType = msoFileTypeNoteItem
.Filename = "*.xls"
If .Execute(SortBy:=msoSortByFileName) > 0 Then
n = .FoundFiles.Count
col1 = 2
ReDim myfile(1 To n) As String
For i = 1 To n
myfile(i) = .FoundFiles(i)
Filename = myfile(i)
aa = InStrRev(Filename, "\")
nm = Right(Filename, Len(Filename) - aa)
nm1 = Left(nm, Len(nm) - 4)
If nm1 <> "汇总表" Then
Workbooks.Open myfile(i)
Dim wb As Workbook
Set wb = ActiveWorkbook
m = [a65536].End(xlUp).Row
arr = Range(Cells(3, 3), Cells(m, 3))
Sht1.Activate
col1 = col1 + 1
Cells(2, col1) = nm '自动获取文件名
Cells(3, col1).Resize(UBound(arr), 1) = arr
wb.Close savechanges:=False
Set wb = Nothing
End If
Next
Else
MsgBox "该文件夹里没有任何文件"
End If
End With
[a1].Select
Set myFs = Nothing
Application.ScreenUpdating = True
End Sub
至于数值显示引用地址,会导致全是公式,速度会很慢,再说要复核校验一般是打印出来再查的,在电脑上切换来切换去的并不方便的。 |
|