PDA

View Full Version : Copy each page of a document after itself



Dueno
06-22-2015, 05:43 AM
Hi,

I've been struggling with this for a week now and can't get it it to work.

For a client I create documents with orders. It can range from 1 to 5 pages.
For security purposes they need a copy of each page.

What they want is that each page will be copied after itself in the document:

So page 1 will be copied to page 2, page 3 (former page 2) will be copied after page 3 and so on for as long as there are pages left.

I've been looking everywhere and trying different things but either messes up the formatting or it doesn't work at all,


Does anyone have an idea on how to solve this, or at least give me a push in the right direction?

I've added an example document 13751

Kind regards, Raymond

Here is the code that i have, it copies everything but only to the end not on the desired page:


Sub Demo()
Dim Rng As Range
With ActiveDocument
Dim varNumberPages As Variant
Dim i As Integer


varNumberPages = ActiveDocument.Content.Information(wdActiveEndAdjustedPageNumber) + 1
For i = 1 To varNumberPages
Set Rng = .GoTo(What:=wdGoToPage, Name:=i)
Set Rng = Rng.GoTo(What:=wdGoToBookmark, Name:="\page")
Rng.Copy
With .Range.Characters.Last
.InsertBefore vbCr & Chr(12)
.Collapse wdCollapseEnd
.PasteAndFormat (wdFormatOriginalFormatting)
End With
Next i
End With
End Sub