ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 1807|回复: 2

求高手指教,多个表格合并?急

[复制链接]

TA的精华主题

TA的得分主题

发表于 2012-9-1 12:30 | 显示全部楼层 |阅读模式
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
我有一套表,其中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
自已不懂怎么修改,请高手指教。

TA的精华主题

TA的得分主题

 楼主| 发表于 2012-9-1 14:58 | 显示全部楼层
从发一下从网上下的代码,请高手看一下。
  1. '取得该目录下的所有excel文件(包括子目录)
  2. Sub getFolder(strPath As String)
  3. Dim fileCount As Integer
  4. Dim subPath As String
  5. '目录列表
  6. Dim folderList(1000) As String
  7. '目录列表下标
  8. Dim folderCount As Integer
  9. Dim fileList(1000) As String
  10. folderCount = 0
  11. Dim i As Long
  12. '取得目录和文件信息
  13. subPath = Dir(strPath & "", vbDirectory)

  14. Do While subPath <> ""

  15.     '除去上层目录
  16.     If subPath <> "." And subPath <> ".." Then
  17.    
  18.         '如果是目录就加入目录列表
  19.         If GetAttr(strPath & "" & subPath) = vbDirectory Then
  20.         
  21.             folderList(folderCount) = strPath & "" & subPath
  22.             Debug.Print folderList(folderCount)
  23.             folderCount = folderCount + 1
  24.             
  25.         '如果是excel文件就加入文件列表
  26.         ElseIf InStr(Right(subPath, 4), "xls") > 0 Then
  27.         
  28.             fileList(fileCount) = strPath & "" & subPath
  29.             Debug.Print fileList(fileCount)
  30.             fileCount = fileCount + 1
  31.         
  32.         End If
  33.    
  34.     End If
  35.     '取下一个目录或文件
  36.     subPath = Dir
  37. Loop

  38. '如果该目录下还有子目录
  39. If folderCount > 0 Then

  40.     For i = 0 To folderCount - 1
  41.         
  42.         getFolder (folderList(i))
  43.    
  44.     Next i

  45. End If
  46. End Sub
复制代码

TA的精华主题

TA的得分主题

发表于 2012-9-12 10:20 | 显示全部楼层
帮你支持一下,让别人来解决
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-6-3 19:54 , Processed in 0.024386 second(s), 9 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表