Click here to Skip to main content
15,917,062 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi All,

I am trying to create a report with multiple records which will require the word template to be used multiple times. But by my following code every next record starts again from Page 1 deleting the previous record. Please suggest..

Thanks
Atul

VB.NET
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        oWord = CreateObject("Word.Application")
        oWord.Visible = True
        oDoc = oWord.Documents.Add("C:/Template1.dotx")

        Dim i As Integer = 0
        Dim total As Integer = 2

        For i = 0 To total

            If i > 0 Then
                oDoc.Content.InsertFile("C:/Template1.dotx")       
            End If

            oDoc.Bookmarks.Item("Bookmark1").Range.Text = i

            'For page break
            Dim oRng As Word.Range
            oRng = oDoc.Bookmarks.Item("\endofdoc").Range
            oRng.InsertBreak(Word.WdBreakType.wdPageBreak)


        Next

    End Sub
Posted

1 solution

Solution was to use range with start range value and change the value after every loop
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900