Microsoft Developer Network > Forums Home > Microsoft ISV Community Center Forums > Visual Basic for Applications (VBA) > How to copy MSWord complete page and create new page in the same Template
Ask a questionAsk a question
 

AnswerHow to copy MSWord complete page and create new page in the same Template

  • Monday, November 02, 2009 8:08 PMsreeni2219 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I have a MSWord Template. In the Second Page I have a checkbox, if user clicks on that checkbox i want to copy the second page to a third Page, which means i will have 3 pages now if user clicks on the third page checkbox it should create another same page in the template and focus should be the created page. I have tried to create a macro, really i don't have any luck, Could you please help me to resolve this issue.

Answers

  • Monday, November 09, 2009 8:05 AMTim LiMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Hello,

    Please try this code:

    Sub Macro2()

    ' Macro2 Macro
    Selection.GoTo what:=Word.wdGoToPage, which:=Word.wdGoToAbsolute, Count:=2
    Dim rng As Range
    Set rng = Selection.Range
    rng.End = Selection.Bookmarks("\Page").Range.End
    rng.Select
    rng.Copy
    rng.Collapse Word.WdCollapseDirection.wdCollapseEnd
    rng.InsertBreak Word.WdBreakType.wdPageBreak
    Selection.GoTo what:=Word.wdGoToPage, which:=Word.wdGoToAbsolute, Count:=3
    Set rng = Selection.Range
    rng.End = Selection.Bookmarks("\Page").Range.End
    rng.Select
    rng.Paste
    End Sub


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

All Replies

  • Monday, November 09, 2009 8:05 AMTim LiMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Hello,

    Please try this code:

    Sub Macro2()

    ' Macro2 Macro
    Selection.GoTo what:=Word.wdGoToPage, which:=Word.wdGoToAbsolute, Count:=2
    Dim rng As Range
    Set rng = Selection.Range
    rng.End = Selection.Bookmarks("\Page").Range.End
    rng.Select
    rng.Copy
    rng.Collapse Word.WdCollapseDirection.wdCollapseEnd
    rng.InsertBreak Word.WdBreakType.wdPageBreak
    Selection.GoTo what:=Word.wdGoToPage, which:=Word.wdGoToAbsolute, Count:=3
    Set rng = Selection.Range
    rng.End = Selection.Bookmarks("\Page").Range.End
    rng.Select
    rng.Paste
    End Sub


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.