使用另一个主Word文档中的内容附加多个Word文档。

使用另一个主Word文档中的内容附加多个Word文档。

问题描述:

您好,



我的任务是通过添加已定义内容的已定义表格来附加超过2200个Word(2010)文档&nbsp ;每个文档的最后一页。 我希望不必手动执行此操作并且考虑使用循环函数来打开文件夹中保存的每个
文件,找到文档的末尾,插入分页符,转到主文件,将整个(主文件)文档复制并粘贴到文档的末尾。



通过论坛搜索,我找到了Tim Li的一些代码来插入整个将文档转换为另一个:



Selection.InsertFile FileName:=" MasterFile.docx",范围:="",_

ConfirmConversions:= False,Link:= False,Attachment:= False



但是,我不确定如何将其与其他所有内容相结合来完成此任务。



广泛接受任何建议,建议和随机的琐事:)



提前谢谢。

Hello,

I have been tasked to append just over 2200 Word (2010) documents by adding a defined table with defined content to the last page of each document.  I'm hoping not to have to do this manually and was thinking a loop function to open each file saved within the folder, locate the end of the document, insert a page break, go to the master file, copy and paste the entire (master file) document into the end of the document.

Searching through the forum, I did find some code from Tim Li to insert an entire document into another:

Selection.InsertFile FileName:="MasterFile.docx", Range:="",_
ConfirmConversions:=False, Link:=False, Attachment:=False

However, I'm not sure how to incorporate that in with everything else to accomplish this task.

Widely accepting any suggestions, recommendations, and random bits of trivia :)

Thank you in advance.

为自己节省大量工作
http://www.gmayor.com/document_batch_processes.htm
将负责所有文件处理并记录该过程。您需要担心的是将表添加到每个文档的功能。该加载项要求自定义函数采用特定格式,在网页和加载项帮助中描述

To save yourself a lot of work http://www.gmayor.com/document_batch_processes.htm will take care of all the file handling and log the process. All you need to worry about is the function to add the table to each document. The add-in requires a custom functrion to be in a particular format, described on the web page and in the add-in help.

如果要插入相同的数据在每个文档中,我建议在普通模板中使用构建块。在下面的示例中,我调用了构建块"MyTable"并将其保存为普通模板中的自动文本条目(ALT + F3)。
因此,您可以从加载项调用下面的函数,将表格添加到所有文档的末尾。如果你想要它在其他地方根据需要更改oRng的位置。

If identical data is to be inserted in each document, I would suggest using a building block in the normal template. In the following example I have called the building block 'MyTable' and saved it as an autotext entry (ALT+F3) in the normal template. You can thus call the function below from the add-in to add the table to tyhe end of all your documents. If you want it somewhere else change the location of oRng as required.

我建议你在其中一个文件中插入表格,然后保存添加为自动文本条目。您可以使用单个文档进行测试。这样,在将表格插入
更多文档之前,可以考虑文档格式的任何影响。

I woul suggest inserting the table as you want it in one of the documents then save the addition as the autotext entry. You can test with a single document. That way any affect from the document formatting can be accounted for before you insert tables into more documents.

函数AddTable(oDoc As Document)As Boolean

Dim oRng As Range

    On Error GoTo Err_Handler

    oDoc.Range.InsertParagraphAfter
   设置oRng = oDoc.Range

    oRng.Collapse wdCollapseEnd

    Application.Templates(QUOT;&的Normal.dotm QUOT)。 _

            BuildingBlockEntries(" MyTable")。插入_
$
           其中:= oRng,_

            RichText:= True

    AddTable = True

lbl_Exit:

   退出功能

Err_Handler:

    AddTable = False

   恢复lbl_Exit

结束功能

Function AddTable(oDoc As Document) As Boolean
Dim oRng As Range
    On Error GoTo Err_Handler
    oDoc.Range.InsertParagraphAfter
    Set oRng = oDoc.Range
    oRng.Collapse wdCollapseEnd
    Application.Templates("Normal.dotm"). _
            BuildingBlockEntries("MyTable").Insert _
            Where:=oRng, _
            RichText:=True
    AddTable = True
lbl_Exit:
    Exit Function
Err_Handler:
    AddTable = False
    Resume lbl_Exit
End Function