![]() |
Insert Pagebreak in Word document
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 |
Insert Pagebreak in Word document
did you add the reference for the micrtosoft word in the VBA options? if not you need to define the constant Const wdPageBreak = 7 -- joel ------------------------------------------------------------------------ joel's Profile: http://www.thecodecage.com/forumz/member.php?u=229 View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=198796 http://www.thecodecage.com/forumz |
Insert Pagebreak in Word document
I did set the reference, but somehow I must have removed it again. Thanks.
Jan joel wrote: did you add the reference for the micrtosoft word in the VBA options? if not you need to define the constant Const wdPageBreak = 7 |
All times are GMT +1. The time now is 09:00 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com