Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-24-2018, 09:28 AM
dpashley dpashley is offline Copy the only page in Word document a given number of times in VBA Windows 10 Copy the only page in Word document a given number of times in VBA Office 2010 32bit
Novice
Copy the only page in Word document a given number of times in VBA
 
Join Date: Sep 2016
Posts: 6
dpashley is on a distinguished road
Default Copy the only page in Word document a given number of times in VBA

What I need to do is take a set page in a Word document and duplicate (copy & paste) it a set number of times using VBA.



The desired solution is a function that I am able to pass in the number of additional pages I want. The function would then take the only page in the document and add this number of exact copies to the end.

Thanks in advance for any help,

Dan
Reply With Quote
  #2  
Old 01-24-2018, 03:05 PM
macropod's Avatar
macropod macropod is offline Copy the only page in Word document a given number of times in VBA Windows 7 64bit Copy the only page in Word document a given number of times in VBA Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

If you insert a next page section break at the end of the document, unlinking that section's headers/footers from those of the previous sections, then put the entire page you want to replicate into the last Section's header, the following macro will let you make as many copies of that page as you require.
Code:
Sub LastPageCopier()
Application.ScreenUpdating = False
Dim iCount As Long, i As Long
On Error GoTo Done
iCount = InputBox("How many of the last page do you need?", "Last Page Copier", 2)
If IsNumeric(iCount) = False Then GoTo Done: If iCount < 2 Then GoTo Done
For i = 1 To iCount
  ActiveDocument.Range.InsertAfter Text:=Chr(12)
Next
Done:
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 01-24-2018, 10:10 PM
gmayor's Avatar
gmayor gmayor is offline Copy the only page in Word document a given number of times in VBA Windows 10 Copy the only page in Word document a given number of times in VBA Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

While Paul's suggestion is ingenious, you could also do it without modifying the document:
Code:
Sub CopyPage()
Dim oRng As Range, oEnd As Range
Dim lngCopies As Long, i As Long
    lngCopies = InputBox("How many copies?")
    Set oRng = ActiveDocument.Bookmarks("\page").Range
    For i = 1 To lngCopies
        ActiveDocument.Range.InsertAfter Chr(12)
        Set oEnd = ActiveDocument.Range
        oEnd.Collapse 0
        oEnd.FormattedText = oRng.FormattedText
    Next i
lbl_Exit:
    Set oRng = Nothing
    Set oEnd = Nothing
    Exit Sub
End Sub
If you have a page number field in your document, you need to decide how you want the numbering to appear in the finished document. If you want 1 on each page then change the field for '1' as text; however if you do that it is difficult to see the point of the document. If you want to print a number of copies then why duplicate them first? If you want numbered printed copies then see http://www.gmayor.com/automatic_numbering_documents.htm
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #4  
Old 01-25-2018, 02:33 AM
dpashley dpashley is offline Copy the only page in Word document a given number of times in VBA Windows 10 Copy the only page in Word document a given number of times in VBA Office 2010 32bit
Novice
Copy the only page in Word document a given number of times in VBA
 
Join Date: Sep 2016
Posts: 6
dpashley is on a distinguished road
Default

That worked perfectly!

Thank you!
Reply With Quote
Reply

Tags
copy and paste, duplicate, vba



Similar Threads
Thread Thread Starter Forum Replies Last Post
Running Head AND Page Number on First Page of Document (for APA Format) with Word 2003 DBinSJ Word 3 11-23-2016 11:52 AM
Copy the only page in Word document a given number of times in VBA Copy a page from a document James__S Word 4 10-29-2014 12:23 AM
Anyway to copy a complete page full of objects into a new document? MuffinStud Word 1 12-20-2012 04:43 AM
Copy the only page in Word document a given number of times in VBA Word Issue, bottom of document is showing on the screen several times. TerryBlevins Word 1 12-21-2011 12:58 AM
Copy the contents of a dcoument and paste it several times in a new document Gerjanst Word VBA 0 06-30-2010 12:51 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:00 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft