且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将表格,书签和页面插入Word文档的中间

更新时间:2023-11-30 20:18:34

令人惊讶的是,该修复很容易.

Embarrasingly, it turns out the fix is quite easy.

而不是上面的

Set wdRng = .Characters.Last

就像替换为一样简单

Set wdRng = .Paragraphs(2).Range

或者更好的方法是,在要添加内容(表格,书签,分页符等)的位置插入分节符(插入->中断->分节符类型).在文档中间,然后使用:

Or better still, insert a Section Break (Insert->Break->Section Break Type) where you want to add stuff (tables, bookmarks, page breaks, etc). in the middle of the document, and then use:

Set wdRng = .Sections(2).Range
. . . 
. . . 

并且要确保插入顺序正确(不是反向顺序),需要进行以下更改:

And to make sure the order of insertions is correction (not in reverse order), need the following changes:

    Set Rng = .Sections((d - datMin) + 1).Range 'Go to next section each loop
    . . . 
    . . . 

    wdTbl.Range.Characters.Last.Next.InsertBreak wdSectionBreakNextPage  'To add pagebreak . . . instead of .InsertBefore Chr(12) as in original code