none
VBA - Word Duplicate The Page - Many Times RRS feed

  • Question


  • Hi friends,

     

    How do I duplicate a page range a number of times.

    I have tried a number of things but nothing has worked out so I have gone back to the basics.

     

    Below is very rudimentary but I just can't work out how to make a loop to copy and duplicate it 10 times or 20 times etc.

    Sub DuplicatePageXTimes()
    
    '  Copy Paste Block  10
    
    
        Selection.WholeStory
        Selection.Copy
        Selection.PasteAndFormat (wdFormatOriginalFormatting)
        Selection.PasteAndFormat (wdFormatOriginalFormatting)
        Selection.PasteAndFormat (wdFormatOriginalFormatting)
        Selection.PasteAndFormat (wdFormatOriginalFormatting)
        Selection.PasteAndFormat (wdFormatOriginalFormatting)
        Selection.PasteAndFormat (wdFormatOriginalFormatting)
        Selection.PasteAndFormat (wdFormatOriginalFormatting)
        Selection.PasteAndFormat (wdFormatOriginalFormatting)
        Selection.PasteAndFormat (wdFormatOriginalFormatting)
        Selection.PasteAndFormat (wdFormatOriginalFormatting)
    
    End Sub

    Any ideas are appreciated

     

    Thank you



    Cheers Dan :)

    Monday, November 7, 2016 6:06 PM

Answers

  • Hi, 

    If you need to put the same statement 10 times you can simply put like below. Note that this code is not tested. If your previous code was working then this should work as well in same manner.

    Sub DuplicatePageXTimes()
    
    '  Copy Paste Block  10
    
        Dim i As Integer
        Selection.WholeStory
        Selection.Copy
        For i = 1 To 10
             Selection.PasteAndFormat (wdFormatOriginalFormatting)
        Next
    End Sub


    Vish Mishra

    • Marked as answer by Dan_CS Monday, November 7, 2016 8:32 PM
    Monday, November 7, 2016 8:14 PM

All replies

  • Hi, 

    If you need to put the same statement 10 times you can simply put like below. Note that this code is not tested. If your previous code was working then this should work as well in same manner.

    Sub DuplicatePageXTimes()
    
    '  Copy Paste Block  10
    
        Dim i As Integer
        Selection.WholeStory
        Selection.Copy
        For i = 1 To 10
             Selection.PasteAndFormat (wdFormatOriginalFormatting)
        Next
    End Sub


    Vish Mishra

    • Marked as answer by Dan_CS Monday, November 7, 2016 8:32 PM
    Monday, November 7, 2016 8:14 PM
  • Hello Vish,

     

    Nice to see you again.

    I have been looking for this every where :)

     

    I knew it was a loop that I needed but the ranges wouldn’t work and then it got complicated so I had to go back to basics.

     

    Thank you for pointing me in the right direction, I can tweak and add it to some of my other code now yay

     

    Have a great day!


    Cheers Dan :)

    Monday, November 7, 2016 8:32 PM