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
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