none
Text Box is not jumped to top of next page using VB.Net RRS feed

  • Question

  • Hi everybody,

    I am in a trouble to generate some text boxes in word document automatically. It works only in first page. See the picture below. It's a document created using VB.Net

    Thanks in Advance

    Sudheer 

    Dim

    poleft, potop AsInteger

    Dimshp AsWord.Shape

            poleft = oDoc.PageSetup.LeftMargin

            potop = oDoc.PageSetup.TopMargin

            shp = oDoc.Shapes.AddTextbox(Microsoft.Office.Core.

    MsoTextOrientation.msoTextOrientationHorizontal, poleft, potop, 200, 50)

            shp.TextFrame.TextRange.Text =

    "fsfsdfsd"


            poleft = poleft + 100

            potop = potop + 50

            shp = oDoc.Shapes.AddLine(poleft, potop, poleft, potop + 50)

            shp.Line.EndArrowheadStyle = Microsoft.Office.Core.

    MsoArrowheadStyle.msoArrowheadTriangle

            poleft = poleft - 100

            potop = potop + 50

            shp = oDoc.Shapes.AddTextbox(Microsoft.Office.Core.

    MsoTextOrientation.msoTextOrientationHorizontal, poleft, potop, 200, 50)

            shp.TextFrame.TextRange.Text =

    "KKKK"


            poleft = poleft + 200

            potop = potop + 25

            shp = oDoc.Shapes.AddLine(poleft, potop, poleft + 50, potop)

            shp.Line.EndArrowheadStyle = Microsoft.Office.Core.

    MsoArrowheadStyle.msoArrowheadTriangle

            poleft = poleft + 50

            potop = potop - 25

            shp = oDoc.Shapes.AddTextbox(Microsoft.Office.Core.

    MsoTextOrientation.msoTextOrientationHorizontal, poleft, potop, 200, 50)

            shp.TextFrame.TextRange.Text =

    "jjjj"


           

    'oWord.Selection.InsertNewPage()


            poleft = poleft - 150

           

    Dimijj AsInteger


           

    Forijj = 1 To10

                potop = potop + 50

                shp = oDoc.Shapes.AddLine(poleft, potop, poleft, potop + 50)

                shp.Line.EndArrowheadStyle = Microsoft.Office.Core.

    MsoArrowheadStyle.msoArrowheadTriangle

                poleft = poleft - 100

                potop = potop + 50

                shp = oDoc.Shapes.AddTextbox(Microsoft.Office.Core.

    MsoTextOrientation.msoTextOrientationHorizontal, poleft, potop, 200, 50)

                shp.TextFrame.TextRange.Text =

    "BBB"+ Str(ijj) + "top="+ Str(potop)

                poleft = poleft + 100

               

    Ifpotop > 672 Then


                    potop = oDoc.PageSetup.TopMargin

                   

    'oWord.Selection.InsertNewPage()


                   

    'oWord.Selection.ShapeRange(1)


               

    EndIf


           

    Nextijj



    Thursday, April 20, 2017 1:44 PM

Answers

  • Hello, Sudheer 

    I think you need to insert a page break when you want to generate textboxs on a new page.

    Here is my code for inserting a page break.

    If potop >= 672 Then
                    Dim rng As Word.Range
                    With oDoc
                        rng = .Range(.Content.End - 1, .Content.End - 1)
                        rng.InsertBreak(7)
                    End With
                    oWord.Selection.GoToNext(Word.WdGoToItem.wdGoToPage)
    
                    potop = oDoc.PageSetup.TopMargin
                End If

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, April 21, 2017 3:18 AM
    Moderator

All replies

  • Hello, Sudheer 

    I think you need to insert a page break when you want to generate textboxs on a new page.

    Here is my code for inserting a page break.

    If potop >= 672 Then
                    Dim rng As Word.Range
                    With oDoc
                        rng = .Range(.Content.End - 1, .Content.End - 1)
                        rng.InsertBreak(7)
                    End With
                    oWord.Selection.GoToNext(Word.WdGoToItem.wdGoToPage)
    
                    potop = oDoc.PageSetup.TopMargin
                End If

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, April 21, 2017 3:18 AM
    Moderator
  • Thanks a lot Celeste..

    It worked well.... God bless u


    Friday, April 21, 2017 1:08 PM