Add page x of y in word6/18/2023 ![]() 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") If you want to run this code from within Word, there is no need to create a Word.Application object: Sub InsertPageBreaks() 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. |