|
我有一套表,其中sheet1,sheet2,sheet3,sheet4.......sheet8里面都有数据,这样的表共20几份,要把这些表分别汇总到一张表汇总表的sheet1,sheet2,......sheet8.怎么做,我从网上搜了一个代码,看看时否有帮助
'取得该目录下的所有excel文件(包括子目录)Sub getFolder(strPath As String)Dim fileCount As IntegerDim subPath As String'目录列表Dim folderList(1000) As String'目录列表下标Dim folderCount As IntegerDim fileList(1000) As StringfolderCount = 0Dim i As Long'取得目录和文件信息subPath = Dir(strPath & "\", vbDirectory) Do While subPath <> "" '除去上层目录 If subPath <> "." And subPath <> ".." Then '如果是目录就加入目录列表 If GetAttr(strPath & "\" & subPath) = vbDirectory Then folderList(folderCount) = strPath & "\" & subPath Debug.Print folderList(folderCount) folderCount = folderCount + 1 '如果是excel文件就加入文件列表 ElseIf InStr(Right(subPath, 4), "xls") > 0 Then fileList(fileCount) = strPath & "\" & subPath Debug.Print fileList(fileCount) fileCount = fileCount + 1 End If End If '取下一个目录或文件 subPath = DirLoop '如果该目录下还有子目录If folderCount > 0 Then For i = 0 To folderCount - 1 getFolder (folderList(i)) Next i End If End Sub
自已不懂怎么修改,请高手指教。 |
|