简体   繁体   English

在MS-Word中,VBA如何拆分插入分节符和段落标记的表

[英]In MS-Word how do you VBA split a table inserting a Section Break AND a paragraph mark

wdSectionBreakNextPage does not come with a trailing paragraph mark wdSectionBreakNextPage不带有尾随段落标记

I have a massive table i copy from excel to word sprinkled throughout with homemade fields PAGEX and SECTIONX. 我有一张巨大的桌子,我从excel复制到整个自制字段PAGEX和SECTIONX中的单词。 My macro will change these to page and section breaks, splitting the table for each (what I want). 我的宏会将这些更改为分页符和分节符,为每个分页符(我想要的)拆分表。 But page breaks come with a trailing paragraph mark before the table and section breaks do not. 但是分页符在表和分节符之前没有结尾的段落标记。 My feeble attempts to insert a paragraph mark after a section break always ends up with the paragraph mark inside the table. 我试图在分节符后插入段落标记的尝试总是以表格内的段落标记结尾。

My goal is to get the same gap between my header and the beginning of the table after both section breaks and page breaks. 我的目标是在节和分页符断开之后,在标题和表的开头之间保持相同的距离。 I think I simply want a macro to insert a paragraph mark after my section breaks similar to the way wdPageBreak works (ie, between the break and the table). 我想我只是希望宏在我的部分中断后插入一个段落标记,类似于wdPageBreak的工作方式(即,在中断和表之间)。 But I'm open to suggestions. 但我愿意提出建议。

As perhaps further clarification, doing this manually involves creating a new row after a section break, then converting that row to text (quite impractical for the counts I'm looking at). 也许需要进一步澄清,手动执行此操作需要在分节符之后创建一个新行,然后将该行转换为文本(对于我正在查看的计数来说,这是不切实际的)。

    Do While .Execute
        Selection.Delete
        Selection.InsertBreak Type:=wdSectionBreakNextPage
    Loop

尝试:

ActiveDocument.Compatibility(wdSplitPgBreakAndParaMark) = False

thanks free and macro. 感谢免费和宏。 i probably should have noted that i'm a vba novice (cut-and-paste mostly). 我可能应该注意到我是vba新手(主要是剪切粘贴)。 i decided it was easiest to just insert a page break after each section break, and then do a replace of ^m^p by ^p. 我认为最简单的方法是在每个分节符之后插入一个分页符,然后用^ p替换^ m ^ p。

this works in my case, but won't work for others reading this if they have existing page breaks they don't want to lose. 这对我来说是有效的,但如果其他人不希望丢失已有的分页符,则不适用于其他阅读本文的人。

GJ GJ

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM