How to set page breaks in word 20166/28/2023 For instance, don't use Selection without qualifying it. Otherwise you run the risk of creating an extra Word.Application object that isn't controlled by you. If you want to run the code from another application without setting a reference to the Word object library, you must replace all Word-specific constants with their values, and take great care to make all objects refer back directly or indirectly to the Set doc = Documents.Open("c:\report.txt") Note: there is an unavoidable gap around all of the grouped cells. The document uses a Directory merge, which only requires a single set of cells and a two-column page layout, and none of your DOCVARIABLE fields. If you want to run this code from within Word, there is no need to create a Word.Application object: Sub InsertPageBreaks() Re: MS Word Mail Merge - insert page break after new data set begins See attached. Your code is a mixture between early binding (it refers to Word-specific constants such as wdParagraph) and late binding (word and doc are declared as objects). Selection.Collapse Direction:=wdCollapseEnd Selection.MoveDown unit:=wdParagraph, Count:=1 PageSetup.RightMargin = InchesToPoints("0.5") PageSetup.LeftMargin = InchesToPoints("0.5") PageSetup.Orientation = wdOrientLandscape Set word = CreateObject("word.application") But I don't know why page break only inserted before instead of the whole document. I'm trying to insert page break in a Word document with using VBA.
0 Comments
Leave a Reply. |