0
votes

I have a VBScript that creates a big Word document. I need to have it insert a page break at the end so I can insert another select of text however I can't get the page break to work.

I've tried

objWord.Documents(tempFile).Activate
Set objSelection = objWord.Selection
objSelection.InsertBreak(7)
objWord.Documents(tempFile).Activate
Set objSelection = objWord.Selection
objSelection.InsertBreak(wdPageBreak)
objWord.Documents(tempFile).Activate
Set objSelection = objWord.Selection
objSelection.InsertBreak Type:=7
objWord.Documents(tempFile).Activate
Set objSelection = objWord.Selection
objSelection.InsertBreak Type:wdPageBreak

It just skips over it an inserts all the text without creating a page break.

1
VBScript or VBA? You've tagged both. They're not the same. Your title says VBA. Your first paragraph says VBScript.Bond

1 Answers

2
votes

I'm assuming you're using VBScript, since you're referencing Word using objWord instead of the Application object. I'm also assuming you have On Error Resume Next declared because you should be receiving an error trying to use some of those methods in VBScript. The param:=value syntax is not part of VBScript. Also, constants like wdPageBreak need to be explicitly declared in your script.

Since wdPageBreak is the default break type for InsertBreak(), you can just omit it completely. You may want to make sure you're truly at the end of your document, however. For that, you can use Selection.EndKey(), passing the value of wdStory. For example:

Const wdStory = 6

objWord.Selection.EndKey wdStory
objWord.Selection.InsertBreak       ' No param needed here