vba When inserting file, margins in new section disappearing

时光毁灭记忆、已成空白 提交于 2020-01-06 07:04:21

问题


I want to insert DocB' into DocA using the VBA code: Selection.InsertFile DocB.

DocA is a normal document in every regard.

DocB has 2 sections. The first is 'normal' stuff. The second section (properly marked with a Section Break/Next Page) has a new set of left and right margins.

When DocB is inserted into DocA with the above VBA command, all formatting (fonts, spacing, etc.) EXCEPT that the margins in the second section of DocB don't carry into DocA. (The Section Break/New Page marker is still present and visible in the 'assembled' document.)

Why are my margins being erased/ignored with a Selection.InsertFile command?

(I can manually copy and paste the content of DocB into DocA without issue.)


回答1:


Word stores margin settings, headers, footers and similar layout information in the section breaks. For the last section of a document (or the only section if there are no section breaks) this information is stored "in" the last paragraph mark.

When you copy/paste a document, that last paragraph mark with the section formatting is included.

When you use VBA to insert a file, that last paragraph mark is cut off. That's why you're losing the margins. In order to retain that information, before you insert the file you need to add a section break (probably continuous) to the end of the document. This is basically what the Master-/Subdocument functionality does, by the way.



来源:https://stackoverflow.com/questions/48962749/vba-when-inserting-file-margins-in-new-section-disappearing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!