Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 1848|回复: 5

[已解决]怎么可以合并每个工作簿的第一个工作表到一个工作簿里

[复制链接]
发表于 2012-10-28 14:20 | 显示全部楼层 |阅读模式
怎么可以合并每个工作簿的第一个工作表到一个工作簿里
最佳答案
2012-10-28 17:38
  1. Sub Macro1()
  2.      Dim MyPath$, MyName$, lc&, m&, sh As Worksheet
  3.      Set sh = ActiveSheet
  4.      MyPath = ThisWorkbook.Path & ""
  5.      MyName = Dir(MyPath & "*.xls")
  6.      Application.ScreenUpdating = False
  7.      sh.UsedRange.Clear
  8.      Do While MyName <> ""
  9.          If MyName <> ThisWorkbook.Name Then
  10.              m = m + 1
  11.              With GetObject(MyPath & MyName)
  12.                  With .Sheets(1)
  13.                      If m = 1 Then lc = 1 Else lc = .[a1].CurrentRegion.Columns.Count + 1
  14.                      .[a1].CurrentRegion.Copy sh.Cells(1, lc)
  15.                  End With
  16.                  .Close False
  17.              End With
  18.          End If
  19.          MyName = Dir
  20.      Loop
  21.      Application.ScreenUpdating = True
  22.      MsgBox "完毕"
  23. End Sub
复制代码
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2012-10-28 14:36 | 显示全部楼层
回复

使用道具 举报

发表于 2012-10-28 15:17 | 显示全部楼层
是第一个表1中的所有单元各都到一个里面?还是要分开相应单元格
回复

使用道具 举报

发表于 2012-10-28 15:27 | 显示全部楼层
没有附件,谁知道是啥要求??!!
回复

使用道具 举报

发表于 2012-10-28 17:38 | 显示全部楼层    本楼为最佳答案   
  1. Sub Macro1()
  2.      Dim MyPath$, MyName$, lc&, m&, sh As Worksheet
  3.      Set sh = ActiveSheet
  4.      MyPath = ThisWorkbook.Path & ""
  5.      MyName = Dir(MyPath & "*.xls")
  6.      Application.ScreenUpdating = False
  7.      sh.UsedRange.Clear
  8.      Do While MyName <> ""
  9.          If MyName <> ThisWorkbook.Name Then
  10.              m = m + 1
  11.              With GetObject(MyPath & MyName)
  12.                  With .Sheets(1)
  13.                      If m = 1 Then lc = 1 Else lc = .[a1].CurrentRegion.Columns.Count + 1
  14.                      .[a1].CurrentRegion.Copy sh.Cells(1, lc)
  15.                  End With
  16.                  .Close False
  17.              End With
  18.          End If
  19.          MyName = Dir
  20.      Loop
  21.      Application.ScreenUpdating = True
  22.      MsgBox "完毕"
  23. End Sub
复制代码
回复

使用道具 举报

发表于 2012-10-28 20:06 | 显示全部楼层
多表合并不知道车车老师的那个邮件插件里的功能可不可以实现呢?当然,自己用VB肯定也是可以的,能用现成的就省点心吧{:061:}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-5-19 20:18 , Processed in 0.225938 second(s), 11 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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