|
楼主 |
发表于 2016-8-27 08:33
|
显示全部楼层
这是之前别人发我的汇总,只要改一下Cells(n, 2) = "='" & fn & "1'!o20"这里面的某些数据就可以适应不同资料的汇总,现在用不了了,不晓得哪里出问题了
Sub 汇总()
Dim myDialog As FileDialog, oFile As Object, strName As String, n As Integer
Dim FSO As Object, myFolder As Object, myFiles As Object
Dim fn$
Set myDialog = Application.FileDialog(msoFileDialogFolderPicker)
n = 6
With myDialog
If .Show <> -1 Then Exit Sub
Set FSO = CreateObject("Scripting.FileSystemObject")
Set myFolder = FSO.getfolder(.InitialFileName)
Set myFiles = myFolder.Files
For Each oFile In myFiles
strName = UCase(oFile.Name)
strName = VBA.Right(strName, 3)
If strName = "XLS" Then
Cells(n, 1) = oFile.Name
fn = myFolder & "\[" & Cells(n, 1) & "]"
Cells(n, 2) = "='" & fn & "1'!o20"
Cells(n, 3) = "='" & fn & "1'!o21"
Cells(n, 4) = "='" & fn & "1'!o22"
Cells(n, 6) = "='" & fn & "1'!o23"
Cells(n, 10) = "='" & fn & "1'!o24"
Cells(n, 11) = "='" & fn & "1'!o25"
n = n + 1
End If
Next
End With
End Sub
|
|