Insert Pagebreak in Word document

J

Jan Kronsell

I have this code

Sub Flet()
Dim Wdapp As Object
Dim Navn As String
Dim Adr As String
Dim PostnrBy As String

On Error Resume Next
Set Wdapp = GetObject(, "Word.application")
If Err.Number <> 0 Then
Set Wdapp = CreateObject("Word.Application")
End If
Wdapp.Documents.Add
For Each c In Range("A2:A20")

If c.Value = "" Then Exit For Else
Navn = c.Value
Adr = c.Offset(0, 1).Value
PnrBy = c.Offset(0, 2).Value & " " & c.Offset(0, 3).Value

Wdapp.Selection.TypeText Text:=Navn
Wdapp.Selection.TypeParagraph
Wdapp.Selection.TypeText Text:=Adr
Wdapp.Selection.TypeParagraph
Wdapp.Selection.TypeText Text:=PnrBy
Wdapp.Selection.TypeParagraph
Wdapp.Selection.TypeParagraph
Wdapp.Selection.TypeParagraph
Wdapp.Selection.TypeText Text:="Dear " & Left(Navn, InStr(1,
Navn, " "))
Wdapp.Selection.TypeParagraph
Wdapp.Selection.InsertBreak Type:=wdPageBreak
Next c
Wdapp.Visible = True
Wdapp.Activate
Set Wdapp = Nothing

End Sub

And it works perfectly Ok, except for the pagebreak, that I would like to
appear after the line Dear ... The line Wdapp.Selection.InsertBreak
Type:=wdPageBreak is apparently ignored. Is there any other way I could
insert a pagebreak in my document, so the next run of trhe For Each...Next
loop is done on a new page?

Jan
 
J

joel

did you add the reference for the micrtosoft word in the VBA options?

if not you need to define the constant

Const wdPageBreak = 7
 
J

Jan Kronsell

I did set the reference, but somehow I must have removed it again. Thanks.

Jan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top