How to duplicate certain pages a number of times by Word VBA?

Discussion in 'Word VBA' started by cyberdude, Feb 3, 2008.

  1. cyberdude

    cyberdude Guest


    I have a long MS Word document and I want to duplicate some pages, say
    P.1 and P.3, several times by VBA. How can I make it? I want to
    choose the pages I want to duplicate and the number of times of
    duplication in the VBA code. Thank you.

    cyberdude, Feb 3, 2008
    1. Advertisements

  2. cyberdude

    Tony Jollans Guest

    Unless your pages are separate by manual page breaks this is likely to go
    wrong. With that caveat, this is fairly basic code to do it

    Page = InputBox("Please Enter Page Number")
    Count = InputBox("Please Enter Number of times to duplicate")
    With Selection
    .GoTo wdGoToPage, wdGoToAbsolute, Page
    For i = 1 To Count: .Paste: Next
    End With
    Tony Jollans, Feb 3, 2008
    1. Advertisements

  3. cyberdude

    cyberdude Guest

    Thanks for your reply.

    What if I want to copy P.2 to P.4 to the end of the same document 3
    I'll be glad to you if you can provide me with the code. Thank you.

    cyberdude, Feb 9, 2008
  4. cyberdude

    Tony Jollans Guest

    This is slightly more complicated but, with the same caveat as before, this
    should do it:

    Page1 = InputBox("Please Enter First Page Number")
    Page2 = InputBox("Please Enter Last Page Number")
    Count = InputBox("Please Enter Number of times to duplicate")
    With ActiveDocument.Range
    .Start = .GoTo(wdGoToPage, wdGoToAbsolute, , Page1).Start
    .End = .GoTo(wdGoToPage, wdGoToAbsolute, , Page2 + 1).Start
    End With
    With ActiveDocument.Range
    For i = 1 To Count
    .Collapse wdCollapseEnd
    End With

    Completely off-topic: I see you sign yourself as Mike here but as David in
    another post. Do you have a real name?
    Tony Jollans, Feb 10, 2008
  5. cyberdude

    cyberdude Guest

    Hi Tony,

    Thank you for your reply which is very useful.
    I used David as my pseudonym. I put down David in almost all of my
    past posts.
    My real name is Michael or Mike. I think I had better use Mike from
    now on to make my name be consistent. Thanks again!

    cyberdude, Feb 11, 2008
  6. cyberdude


    Op maandag 11 februari 2008 13:18:29 UTC+1 schreef cyberdude:
    Its been a while when this thread is being updated but maybe someone can help me. The first macro does everything i need. It copies a page en past it right after that page.

    The second macro copies a range of pages en past them at the end of the document.

    I need to combine those two macro's. What i reallly could use is: Copy a range off page (just like in macro 2) and past the right after the copied pages. (just like in macro 1) and not at the end of the document. (like in Macro 2)

    Hope you guys are still active and maybe can help me.

    Kind regards,

    , Mar 18, 2014
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.