Discussion:
How to duplicate certain pages a number of times by Word VBA?
(too old to reply)
cyberdude
2008-02-03 08:36:17 UTC
Permalink
Hi,

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.

Mike
Tony Jollans
2008-02-03 17:49:29 UTC
Permalink
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
.Bookmarks("\Page").Range.Copy
For i = 1 To Count: .Paste: Next
End With
--
Enjoy,
Tony
Post by cyberdude
Hi,
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.
Mike
cyberdude
2008-02-09 13:11:37 UTC
Permalink
On 2$B7n(B4$BF|(B, $B>e8a(B1$B;~(B49$BJ,(B, "Tony Jollans" <My forename at my surname dot com>
Post by Tony Jollans
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
.Bookmarks("\Page").Range.Copy
For i = 1 To Count: .Paste: Next
End With
--
Enjoy,
Tony
Thanks for your reply.

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

Mike
Tony Jollans
2008-02-10 11:43:33 UTC
Permalink
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
.Copy
End With
With ActiveDocument.Range
For i = 1 To Count
.Collapse wdCollapseEnd
.Paste
Next
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?
--
Enjoy,
Tony
Post by cyberdude
On 2$B7n(B4$BF|(B, $B>e8a(B1$B;~(B49$BJ,(B, "Tony Jollans" <My forename at my surname dot com>
Post by Tony Jollans
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
.Bookmarks("\Page").Range.Copy
For i = 1 To Count: .Paste: Next
End With
--
Enjoy,
Tony
Thanks for your reply.
What if I want to copy P.2 to P.4 to the end of the same document 3
times?
I'll be glad to you if you can provide me with the code. Thank you.
Mike
cyberdude
2008-02-11 12:18:29 UTC
Permalink
On 2$B7n(B10$BF|(B, $B2<8a(B7$B;~(B43$BJ,(B, "Tony Jollans" <My forename at my surname dot com>
Post by Tony Jollans
This is slightly more complicated but, with the same caveat as before, this
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
.Copy
End With
With ActiveDocument.Range
For i = 1 To Count
.Collapse wdCollapseEnd
.Paste
Next
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?
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!

Mike
m***@gmail.com
2014-03-18 09:20:41 UTC
Permalink
On 2月10日, 下午7時43分, "Tony Jollans" <My forename at my surname dot com> wrote: > 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 > .Copy> End With> With ActiveDocument.Range > For i = 1 To Count> .Collapse wdCollapseEnd> .Paste > Next> 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?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!Mike
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,

Martijn

Loading...