PDA

View Full Version : Solved: Tool to copy and paste a page



Sirfanta
06-13-2007, 06:47 AM
I?m trying to make a tool that copies my current page,
makes a new page below current page and pastes in the copied part.

The problem is that I need a code that tells me which page I?m in,
and how to make a new page in the same section.

Can somebody help me? =)



Public Sub CopyPage
Dim SettPage

<code to get page>

Selection.GoTo(wdGoToPage, wdGoToAbsolute, SettPage) _
.Bookmarks("\Page").Range.Copy

<Code to make page>

Selection.Paste

End Sub

lucas
06-13-2007, 07:19 AM
This is crude and Gerry will tell me how to fix it later but it seems to work:
click in the sheet you wish to copy an run it...it copies the page your on..inserts a page right below it and pastes the first page contents to it.
Sub GrabPage()
Selection.GoTo What:=wdGoToBookmark, Name:="\page"
Selection.Copy
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.Paste
End Sub

lucas
06-13-2007, 07:46 AM
This seems to work a little better...still not right.
Sub GrabPage()
Selection.GoTo What:=wdGoToBookmark, Name:="\page"
Selection.Copy
Selection.InsertBreak Type:=wdSectionBreakNextPage
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.Paste
End Sub

fumei
06-13-2007, 01:24 PM
Selection...bleech, bleeech, bleeech.Sub CopyCurrentPage()
Dim r As Range
Set r = ActiveDocument.Bookmarks("\page").Range
With r
.Copy
.Collapse Direction:=wdCollapseEnd
.InsertBreak Type:=wdPageBreak
.Paste
End With
Set r = Nothing
End SubNote the page break is a PageBreak, not a SectionBreakNextPage, as I see the request was for a
how to make a new page in the same section.My emphasis.

If you indeed do want a SectionBreak, then use SectionBreakNextPage (or OddPage, or whatever).

fumei
06-13-2007, 01:28 PM
Although, I have to ask...

What is the business case for a tool that copies the current page to the next (newly created) page?

Oh, and Steve?

but it seems to work: click in the sheet you wish to copyMy emphasis. Ah, you Excel guys. Just can't escape can you?

fumei
06-13-2007, 01:39 PM
Oh, and I also would like to point out that if there is an existing page after the current page (the one to be copied) it makes a HUGE difference as to how that existing next page is initiated.

IF it is the next page because of a hard page break, then there will be an extra page break, and an empty page.

IF it is the next page because text just flowed into it, then this will be duplicated.

This can be tested for, and the code adjusted easily.

lucas
06-13-2007, 01:42 PM
I know Gerry...should have stayed out of it. I just made things worse. It looked easy when I started....sure glad you came along.

fumei
06-13-2007, 10:38 PM
No! No! Never stay out of it!

A - you certainly did not make anything worse.

B - you will learn more of Word yourself...much more than I will ever learn Excel.

C - I would hate to see you stop, as I would miss the opportunities to correct you.

Just kidding. On C that is.

Sirfanta
06-13-2007, 11:32 PM
My bade. I have a document that contains 60 pages, most of them are table.
When the template is opened there the user can pic what is going to be in the document. The macro deletes pages that are not inn use. But the problem is that some of the pages/forms are going to be used 1 or 10times. So I need ?insert the same page button.?
The pages are all in different sections because of the header. But the header shall be the same on the current page and the copied page.



Dim r As Range
Set r = ActiveDocument.Bookmarks("\page").Range
With r
.Copy
.Collapse Direction:=wdCollapseEnd
'.InsertBreak Type:=wdPageBreak
.Paste
End With
Set r = Nothing




This seems to work fine :bow:


Thank lucas and fumei :friends: