Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

copy page from one word file to another 1

Status
Not open for further replies.

mscallisto

Technical User
Jun 14, 2001
2,990
US
This has to be very easy but I can't seem to find a good solution.

I need to copy pages from one word2000 doc to another.

The "from" doc has pages with one or more bitmaps per page all of which are placed inside text boxes that may overlay one another a bit.

The "to" doc has just text.

I need to insert page 3 of the "from" doc between pages 1 and 2 of the "to" doc.

Copy and Paste doesn't seem to work because I don't know how to select a complete page that has multiple text boxes with pics inserted.
 
How about on the source document, deleting the first and last pages so that only the page you want is left. Use SaveAs to save it with another docname. Then in the destination document, use Insert, File in the appropriate place.

Regards: tf1
 
Code:
Sub CopyPage3()
Dim r As Range
Dim aDoc As Document
Dim OtherDoc As Document

Set aDoc = Documents("CopyFrom.doc")
Set OtherDoc = Documents("CopyTo.doc")
Set r = aDoc.Bookmarks("\page").Range

r.Copy
OtherDoc.Activate
    Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="3"
    Selection.Paste
Set r = Nothing
Set OtherDoc = Nothing
Set aDoc = Nothing
End Sub

NOTES

1. the variable "r" is set for the CURRENT page of the active document. It could be set for something else. You coukd use selection.goto to pick up whatever page you wanted; or you could copy pages sequentially.

2. both documents are loaded. If you need to open the other file (or the originating file) you woukd have to add that.

The above code will copy all content from the page, as is, to the selected location. Please also note that because page start and end - unless explicitly set - are relative, you may copy a page content, but that does NOT mean it will be a page in the new document. The content may end up over a number of pages.

Gerry
 
Thanks to both...so far.

I did say:
I need to insert page 3 of the "from" doc between pages 1 and 2 of the "to" doc.

I should have said I need to insert many pages of the "from" doc between different pages of the "to" doc.

I noticed that I can do the following
Insert > file > range > bookmark name.

Will this help me?

I haven't messed with bookmarks but noticed it referred to in fumei's code.
 
So adjust my code.

Make two variables. One to take what page to copy from the "FROM" doc, the second to set what page it should be copied to, in the "TO" doc.

These could could also be set up as an array from a user input form. That is, ask what pages are to be copied, and where are they going. Store them, and them process them.

This would not be difficult at all.

Gerry
 


Thanks fumei...I'm trying

I tried a simple case but error out on bad file name at: Set aDoc = line.

Code:
Sub CopyPage()
Dim r As Range
Dim s As Range
Dim aDoc As Document
Dim OtherDoc As Document

Set aDoc = Documents("C:\Documents and Settings\smills\Desktop\From.doc")
Set OtherDoc = Documents("C:\Documents and Settings\smills\Desktop\To.doc")
Set r = aDoc.Bookmarks("\page 2").Range
Set s = OtherDoc.Bookmarks("\page 2").Range

r.Copy
OtherDoc.Activate
    Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="2"
    Selection.Paste
Set r = Nothing
Set s = Nothing
Set OtherDoc = Nothing
Set aDoc = Nothing
End Sub

Also it seems like it could be a bit messy if I have 15 0r 20 pages to insert.

If I insert page 2 of "FROM.doc" to page 2 of "TO.doc", then my "TO.doc" file get renumbered? e.g. is page two now page three because of the insertion?

I love code because it's kind of permanent but is there no other way to insert a single page from one doc to another no matter whats on the page of the doc to be copied?
 
The set aDoc = line does does OPEN the file - it seems your code is trying to do this. Documents("Filename") refers to an object (a file) in the Documents Collection. This is a collection of loaded documents. Notice that in my code there is no path in front of the filename. You need to open the file, then set it.

Application.Documents.Open Filename:="C:\Documents and Settings\smills\Desktop\From.doc"

Set aDoc = ActiveDocument


Application.Documents.Open Filename:= "C:\Documents and Settings\smills\Desktop\To.doc"

Set OtherDoc = ActiveDocument

Does the inserted page make the page numbering change? Yes, of course it does. You have another page in there.

Is there another way? Have you tried all other ways? PasteSpecial? Have you tried carefully selecting the entire page and doing a copy and paste?

Actually, as your situation is NOT just a single page, but multiple pages, code is probably a better way of doing it. Properly set up (and yes, that is where the most work is) you can input all the originating pages, all the destination pages, and then click Go, and it will do it all.

Gerry
 
Have you tried carefully selecting the entire page and doing a copy and paste?

Finally I discovered that with Shift Key and clicking each Testbox on the page I am able to select all of the page and paste. I had been trying the Ctrl Key which doesn't work the way I expected.

I will get the code up and running for future use.

Thanks kindly for your patience fumei

sam
 
The Control Key is for Copying the drawing object: the Shift key is for multiple selection of the objects. Of course, once you have made multiple selections, you should be able to group the objects and move them as a single item.

Regards: tf1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top