打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
31,多工作簿汇总(vbDirectory)

'31,多工作簿汇总(vbDirectory)

'2012-9-23

'http://club.excelhome.net/forum.php?mod=viewthread&tid=924305&page=1#pid6330929

Sub ts()

    Dim myPath$, subPath$,shcount&, wb As Object

    Dim subPaths() As Byte,br()

    Dim i&, j&,k&, t!

    t = Timer

   Application.ScreenUpdating = False

    myPath =ThisWorkbook.PATH & "\绩效管理\"

    subPath = Dir(myPath,vbDirectory)

    Do While subPath<> ""

       If subPath <> "." And subPath <> ".." Then

           k = k + 1

           ReDim Preserve subPaths(1 To k)

           subPaths(k) = Val(Replace(subPath, "月份", ""))

       End If

       subPath = Dir

    Loop

    For i = 1 ToUBound(subPaths) - 1

       For j = i + 1 To UBound(subPaths)

           If subPaths(i) > subPaths(j) Then

               Temp = subPaths(i): subPaths(i) = subPaths(j): subPaths(j) = Temp

           End If

       Next j

    Next i

    For i = 1 ToUBound(subPaths)

        myPath1= myPath & subPaths(i) & "月份\"

       myfile = Dir(myPath1 & "*.xls*")

       Do While myfile <> ""

           Set wb = GetObject(myPath1 & myfile)

           With wb

               For j = 1 To .Sheets.Count

                   ar = .Sheets(j).[a3].Resize(.Sheets(j).Cells(Rows.Count, 1).End(3).Row - 2, 13)

                   ReDim Preserve br(1 To 13, 1 To UBound(ar) + myRows)

                   For m = myRows + 1 To UBound(ar) + myRows

                       For n = 1 To 13

                           br(n,m) = ar(m - myRows, n)

                       Next n

                   Next m

                   myRows = myRows + UBound(ar)

               Next j

               .Close False

           End With

           myfile = Dir

        Loop

    Next i

   Sheet2.[A2:M65536].ClearContents

   Sheet2.[a2].Resize(UBound(br, 2), UBound(br)) = Application.Transpose(br)

   Application.ScreenUpdating = True

    MsgBox "数据汇总完成!用时: " & Format(Timer -t, "0.00s")

End Sub

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
制作Excel超链接目录 | VBA实例教程
excel-vba应用示例之将同一文件夹中的多个文本文件读入到工作簿中 Excel教程 o...
不同文件下批量创建特定文件夹
用VBA提取路径下所有工作簿的工作表名(四个方法)
Excel|VBA不打开的情况下获取其它工作簿中的值,指定文件夹下工作簿名字模糊搜索定位|文件夹
调用Dos中的Dir命令遍历目标文件夹内所有文件、以及所有子文件夹中的所有文件
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服