Excel精英培训网

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

[已解决]请问如何将多个word文档中的表格信息汇总到一个word中

[复制链接]
发表于 2016-3-24 12:08 | 显示全部楼层 |阅读模式
请问如何将多个word文档中的表格信息汇总到一个word中
最佳答案
2016-3-24 19:34
Sub abc()
ThisDocument.Content.Delete
    myfile = Dir(ThisDocument.Path & "\*.doc")
    Do While myfile <> ""
    If myfile <> ThisDocument.Name Then
        Set doc = GetObject(ThisDocument.Path & "\" & myfile)
        doc.Tables(1).Range.Copy
        ThisDocument.Activate
        Selection.Paste
        Selection.MoveDown Unit:=wdLine, Count:=1
        doc.Close False
    End If
      myfile = Dir
    Loop
End Sub
材料(多个word文档中的表格汇总为一个word).zip (29 KB, 下载次数: 27)

材料(多个word文档中的表格汇总为一个word).zip

24.11 KB, 下载次数: 14

发表于 2016-3-24 12:29 来自手机 | 显示全部楼层
回复

使用道具 举报

发表于 2016-3-24 12:34 | 显示全部楼层
昨天不是已经回答了你"        从源word文档中取出需要数据到新的word中"的提问?附件也上传了,今天这个问题,只要再遍历一下就可以了。
回复

使用道具 举报

 楼主| 发表于 2016-3-24 13:50 | 显示全部楼层
JX_shangrila 发表于 2016-3-24 12:34
昨天不是已经回答了你"        从源word文档中取出需要数据到新的word中"的提问?附件也上传了,今天这个问题,只要 ...

老师今天这个是多个文档,昨天是在一个文档中。望老师解答。
回复

使用道具 举报

 楼主| 发表于 2016-3-24 13:51 | 显示全部楼层
爱疯 发表于 2016-3-24 12:29
这是重复贴的第一个帖吗

老师不是重复贴。
回复

使用道具 举报

发表于 2016-3-24 14:37 | 显示全部楼层
文件加密不好上传
  1. Sub abc()
  2. ThisDocument.Content.Delete
  3.     myfile = Dir(ThisDocument.Path & "\*.doc")
  4.     Do While myfile <> ""
  5.     If myfile <> ThisDocument.Name Then
  6.         Set doc = Documents.Open(ThisDocument.Path & "" & myfile)
  7.         ActiveDocument.Tables(1).Range.Copy
  8.         ThisDocument.Activate
  9.         Selection.Paste
  10.         Selection.MoveDown Unit:=wdLine, Count:=1
  11.         doc.Close
  12.     End If
  13.       myfile = Dir
  14.     Loop
  15. End Sub
复制代码
QQ截图20160324142949.png
回复

使用道具 举报

 楼主| 发表于 2016-3-24 17:56 | 显示全部楼层
josonxu 发表于 2016-3-24 14:37
文件加密不好上传

老师我试了你的代码,可以将需要信息提取出来。我希望在运行时不要屏闪。请老师指点
回复

使用道具 举报

发表于 2016-3-24 19:34 | 显示全部楼层    本楼为最佳答案   
Sub abc()
ThisDocument.Content.Delete
    myfile = Dir(ThisDocument.Path & "\*.doc")
    Do While myfile <> ""
    If myfile <> ThisDocument.Name Then
        Set doc = GetObject(ThisDocument.Path & "\" & myfile)
        doc.Tables(1).Range.Copy
        ThisDocument.Activate
        Selection.Paste
        Selection.MoveDown Unit:=wdLine, Count:=1
        doc.Close False
    End If
      myfile = Dir
    Loop
End Sub
材料(多个word文档中的表格汇总为一个word).zip (29 KB, 下载次数: 27)
回复

使用道具 举报

 楼主| 发表于 2016-3-25 08:24 | 显示全部楼层
josonxu 发表于 2016-3-24 19:34
Sub abc()
ThisDocument.Content.Delete
    myfile = Dir(ThisDocument.Path & "\*.doc")

老师能介绍下代码的含义不?我是网上搜索了下,有很多语句都没找到。
回复

使用道具 举报

发表于 2016-3-25 09:10 | 显示全部楼层
1261181315a 发表于 2016-3-25 08:24
老师能介绍下代码的含义不?我是网上搜索了下,有很多语句都没找到。

打开目标文件
拷贝第一个表格
在跳转到代码所在的word
粘贴
换行
关闭打开的word

我的思路大致是这个
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-26 12:03 , Processed in 0.356157 second(s), 13 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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