将单词表复制到新的单词文档中

时间:2017-08-26 00:55:20

标签: vba ms-word ms-office word-vba

我有一个word文档,其中包含大约1000个表,每个表都有自己的标题。我希望将这些表分组为100个组(即每组中有10个表),然后将每个组保存在一个新的word文档中(我已保存在桌面上的“newdoc.docx”)。是否有任何VBA代码或宏可以帮助我做到这一点?

1 个答案:

答案 0 :(得分:0)

这是一个让你入门的片段

Sub copyTable()

    ' one table is already in document

    Dim srcDoc As Document
    Set srcDoc = ActiveDocument

    Dim destDoc As Document
    Set destDoc = ActiveDocument    ' same doc in this example

    Dim tabl As Table
    Set tabl = srcDoc.Tables(1)


    Dim rng As Range
    Set rng = destDoc.Range            ' whole doc
    rng.Collapse wdCollapseEnd         ' collapse range into an insert point at end of doc

    tabl.Range.Copy                    ' source table
                                       ' ( could not figure out how to copy directly without copy/paste )
    rng.Paste                          ' paste at insert point

End Sub