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


C

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
 
Ad

Advertisements

T

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
 
C

cyberdude

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

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
 
T

Tony Jollans

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?
 
C

cyberdude

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
 
Ad

Advertisements

M

m.kiepman

Op maandag 11 februari 2008 13:18:29 UTC+1 schreef cyberdude:
On 2月10æ—¥, 下åˆ7時43分, "Tony Jollans" <My forename at my surname dot com> wrote: > This is slightly morecomplicated 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 oftimes 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 whichis 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
 
Ad

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. After that, you can post your question and our members will help you out.

Ask a Question

Top