Excel精英培训网

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

[已解决]文件夹内所有工作簿插入相同的一张工作表

[复制链接]
发表于 2015-6-17 21:58 | 显示全部楼层 |阅读模式
本帖最后由 jk0932 于 2015-6-18 09:25 编辑

如附件所示,
文件夹内有若干个工作簿,现在需要将工作簿“插入表”的Sheet“插入”,插入到其他所以的工作簿中;
效果如:工作簿“Book1结果示范”效果所示,每个工作簿都需要添加一个Sheet“插入”。
谢谢!
最佳答案
2015-6-18 09:05
  1. Sub Macro1()
  2. On Error Resume Next
  3. Dim mypath$, wj$, sht As Worksheet
  4. mypath = ThisWorkbook.Path & ""
  5. Set sht = ThisWorkbook.Sheets("插入")
  6. wj = Dir(mypath & "*.xls*")
  7. Application.ScreenUpdating = False
  8. Application.DisplayAlerts = False
  9. Do While wj <> ""
  10.     If wj <> ThisWorkbook.Name Then
  11.         With Workbooks.Open(mypath & wj)
  12.             If .Sheets("" & sht.Name) Is Nothing Then
  13.                 sht.Copy after:=.Sheets(Sheets.Count)
  14.             End If
  15.             .Close 1
  16.         End With
  17.     End If
  18.     wj = Dir
  19. Loop
  20. Application.DisplayAlerts = True
  21. Application.ScreenUpdating = True
  22. End Sub
复制代码

qiuzhu.rar

67.46 KB, 下载次数: 7

excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2015-6-18 09:05 | 显示全部楼层    本楼为最佳答案   
  1. Sub Macro1()
  2. On Error Resume Next
  3. Dim mypath$, wj$, sht As Worksheet
  4. mypath = ThisWorkbook.Path & ""
  5. Set sht = ThisWorkbook.Sheets("插入")
  6. wj = Dir(mypath & "*.xls*")
  7. Application.ScreenUpdating = False
  8. Application.DisplayAlerts = False
  9. Do While wj <> ""
  10.     If wj <> ThisWorkbook.Name Then
  11.         With Workbooks.Open(mypath & wj)
  12.             If .Sheets("" & sht.Name) Is Nothing Then
  13.                 sht.Copy after:=.Sheets(Sheets.Count)
  14.             End If
  15.             .Close 1
  16.         End With
  17.     End If
  18.     wj = Dir
  19. Loop
  20. Application.DisplayAlerts = True
  21. Application.ScreenUpdating = True
  22. End Sub
复制代码
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-27 07:55 , Processed in 0.329063 second(s), 9 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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