合并 MS Word 文件的工具

发布于 2024-07-08 19:34:54 字数 76 浏览 7 评论 0原文

我有大量的Word 文件需要合并(加入)为一个文件,并且使用Word 合并(一个接一个)会很耗时。 您是否体验过可以完成这项工作的工具?

I have huge number of Word files I need to merge (join) into one file, and will be time consuming to use the Word merger (one by one). Have you experienced any tool that can handle this job?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

泪冰清 2024-07-15 19:34:54
Sub MergeAllDocuments(AllDocumentsPath as String, MasterDocumentPath as String)
  Dim MasterDocument As Document

  Set MasterDocument = Documents.Open(FileName:=MasterDocumentPath)

  TheDocumentPath = Dir(AllDocumentsPath , vbNormal)
  While TheDocumentPath <> ""
    ' Append the next doc to the end of the master doc. (The 
    ' special "\EndOfDoc" bookmark is always available!)
    MasterDocument.Bookmarks("\EndOfDoc").Range.InsertFile TheDocumentPath
    TheDocumentPath = Dir
  Wend

  MasterDocument.Save
End Sub

MergeAllDocuments "C:\MySeparateDocuments\*.doc", "C:\MasterDocument.doc"

我有一个问题 - 为什么你想做这样的事情(至少有“大量”文件)?

Sub MergeAllDocuments(AllDocumentsPath as String, MasterDocumentPath as String)
  Dim MasterDocument As Document

  Set MasterDocument = Documents.Open(FileName:=MasterDocumentPath)

  TheDocumentPath = Dir(AllDocumentsPath , vbNormal)
  While TheDocumentPath <> ""
    ' Append the next doc to the end of the master doc. (The 
    ' special "\EndOfDoc" bookmark is always available!)
    MasterDocument.Bookmarks("\EndOfDoc").Range.InsertFile TheDocumentPath
    TheDocumentPath = Dir
  Wend

  MasterDocument.Save
End Sub

MergeAllDocuments "C:\MySeparateDocuments\*.doc", "C:\MasterDocument.doc"

I have one question - why do you want do do such a thing (with a "huge number" of documents, at least)?

长梦不多时 2024-07-15 19:34:54

不久前我看到了 Graham Skan 的一篇文章。 它可能会让你开始:

Sub InsertFiles()
    Dim strFileName As String
    Dim rng As Range
    Dim Doc As Document
    Const strPath = "C:\Documents and Settings\Graham Skan\My Documents\Allwork\" 'adjust as necessary '"

    Set Doc = Documents.Add
    strFileName = Dir$(strPath & "\*.doc")
    Do
        Set rng = Doc.Bookmarks("\EndOfDoc").Range
        If rng.End > 0 Then 'section break not necessary before first document.'
            rng.InsertBreak wdSectionBreakNextPage
            rng.Collapse wdCollapseEnd
        End If
        rng.InsertFile strPath & "\" & strFileName
        strFileName = Dir$()
    Loop Until strFileName = ""
End Sub

I came across a post by Graham Skan a while back. It might get you started:

Sub InsertFiles()
    Dim strFileName As String
    Dim rng As Range
    Dim Doc As Document
    Const strPath = "C:\Documents and Settings\Graham Skan\My Documents\Allwork\" 'adjust as necessary '"

    Set Doc = Documents.Add
    strFileName = Dir$(strPath & "\*.doc")
    Do
        Set rng = Doc.Bookmarks("\EndOfDoc").Range
        If rng.End > 0 Then 'section break not necessary before first document.'
            rng.InsertBreak wdSectionBreakNextPage
            rng.Collapse wdCollapseEnd
        End If
        rng.InsertFile strPath & "\" & strFileName
        strFileName = Dir$()
    Loop Until strFileName = ""
End Sub
与他有关 2024-07-15 19:34:54

您是否尝试过使用 Word COM api? 你可以自动化很多事情——也许你可以自动化合并。

您确实需要进行实际合并,还是想将文件连接在一起。 这两件事是完全不同的。

当原始文件的两个版本都进行了(可能冲突的)更改时,就会使用合并。 我真的不明白你如何拥有需要将所有文件合并在一起的“大量”文件。 这绝对是一场冲突的噩梦。 您的意思是将它们合并到单独的文件中吗?

当您想要将它们一个接一个地连接起来时,就会发生连接。 这会容易得多。 使用 COM api 完全可以实现这一点。

Have you tried using the Word COM api? You can automate lots of things - maybe you can automate a merge.

Do you really need to do an actual merge, or do you want to join the files together. The two things are quite different.

Merging is used when you have two versions of an original file with (potentially conflicting) changes. I can't really see how you would have a "huge number" of files that you needed to merge all together. This would be an absolute nightmare of conflicts. Do you mean to merge sets of them into individual files?

Joining would be when you want to concatenate them one after the other. This would be a lot easier to do. This is quite possible using the COM api.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文