PDA

View Full Version : Copy page from document to new document



mangaluve
02-24-2009, 09:51 AM
How can I copy a page from a word document into a new document? So I want to create a Form or something, and using VBA I want to take one page (which I decide) from the document and put in in a new document.

fumei
02-24-2009, 10:03 AM
Word does not really understand "page". There are ways to work around this, some very simple, some much more complex.

To copy the current page - i.e. the page the Selection (cursor) is on - to a new document is VERY easy. However, using the easy way means it literally copies the current page. If you have a paragraph that carries over to the next page, what is on the next page will NOT be copied.

"(which I decide)" - how?

mangaluve
02-24-2009, 10:58 AM
Thanks! But can I change the Selection cursor? Basically, I have, say, 10 pages in my document. They are not full, so I dont have to worry about what you say. Is there any way I can change that cursor? And, then, how do I copy that page into a new document, in VBA code

fumei
02-24-2009, 11:14 AM
I am not going to hand over code. Try something, and when (or if) you have problems, ask specific questions.

"Basically, I have, say, 10 pages in my document. They are not full,"

This means to me that you likely have hard page breaks. This is generally speaking not a good idea.

As for changing the cursor, yes, of course you can change the cursor location. However, it would be MUCH better if you never use the cursor at all. You do not need to.

mangaluve
02-25-2009, 02:18 AM
Well I dont really have any idea where to start? This is just a small thing I want to simplify some work-stuff. I don't really care if it should copy a page. I just have a document that is somehow partitioned into several parts (could be new pages, but it doesnt have to be). I want to be able to extract each partition and put it in a new document

fumei
02-25-2009, 01:10 PM
This is just a small thing I want to simplify some work-stuff.

Agreed. It is a small thing. As I stated, it is quite easy...so try doing it. You are not going to be able to do it unless you actually do it.

That being said, I have concerns about:

"I just have a document that is somehow partitioned into several parts (could be new pages, but it doesnt have to be). I want to be able to extract each partition and put it in a new document"

Ummmm. "somehow partioned" does not sound good. First of all "partion" is an expression in your mind. Word does not have a clue what you mean by that. Word has Sections, and it does understand what those are.

Let us use the word "chunk". So you have a document with various "chunks" - "could be new pages, but it doesnt have to be".

OK. Now what? Unless those "chunks" are...ummmm...chunked in a manner that Word understands, then you have a problem.

YOU have to figure out how to make those chunks identified chunks to Word. There are of course ways to do that.

The two basic "chunks" that Word does understand are:

Bookmarks
Sections

It is very easy to extract out a bookmark and make it a new document. Ditto for a Section.

But I will say it again, Word does not really understand "page". Pages are determined (calculated if you will) and they are TOTALLY, TOTALLY TOTALLY dependent on the installed printer driver.

When you have figured out exactly what you want to do, and actually tried doing something, if you have problems with specifics we will be glad to help.

mangaluve
02-25-2009, 02:01 PM
Thanks for your reply. The thing is, imagine I got 10 different word documents (they have a similar structue, for instance a large bold rubric and then some running text). I want to make a form where I can choose a number from 1 to 10. When I've choosen a number (with for instance a textbox) I want to take that document (each number corresponds to one of my ten documents) and put the contents of that document in a new document.

Now this would be pretty simple, given that I don't change the names of my 10 documents, those name could be hard-coded into my "application". But it would be better if all those ten documents could be placed in one single document instead. I want to use some kind of marker (before I thought of a page break, but that won't work well for the reasons you explained). But what is the best and most robust way of doing this? Hope it made sense.

fumei
02-25-2009, 02:12 PM
I give up.

Try doing something. Trying starting with something simple. Make it work. Then expand the scope of what you want to do.

I have a bit of a hard time figuring out what you really want...so I will not try.

"But what is the best and most robust way of doing this?"

Doing WHAT?

At some point you are talking about parts of documents (your "partitions"), and now you are talking about whole documents.

"I want to take that document (each number corresponds to one of my ten documents) and put the contents of that document in a new document."

THAT sounds like you want to compile a bunch of documents into one document.

Sure, that can be done easily.

Can you take chunks of documents and make those chunks into new documents? Sure, that can be done easily.

However, nothing is going to get done until you figure out what it is you actually want to do...and try doing it.

mangaluve
02-25-2009, 03:37 PM
Dont kill me man... "I want to take "that document", that came out wrong, my english isn't the best. I want to compile all ten documents into one document, then be able to pick out the different documents from this "large document". And I don't know where to start at all...

lucas
02-25-2009, 04:15 PM
http://vbaexpress.com/forum/showthread.php?t=20211


http://vbaexpress.com/forum/showthread.php?t=13543

fumei
02-26-2009, 09:56 AM
OK, I am not trying to kill you, I am trying to understand what it is you want to do. Believe it or not, I am actually trying to help.

You have to be clear. You first asked about making a page into a document, then asked merging whole documents into a document.

Both of these can be done. Steve (lucas) has posted links to two threads that may be of help.

You state you do not know where to start. I have replied that you start with something. Record a macro. Try searching for similar types of requests. Give at least something a try and when you have problems post the code you have actually tried and we will help you either fix it, or suggest improvements.

My essential point is that YOU must determine what it is exactly what you want to do.

For example, you state:

"I want to compile all ten documents into one document, then be able to pick out the different documents from this "large document".

OK, fair enough. That can be done. I just tried doing a test which does that and I got it to do that with a few lines of code. Done. Each document is brought in and individually bookmarked, so that it is very straightforward to "pick out" each individual document "chunk" afterwords.

Except...

I made the decision to separate each of those document "chunks" by a Section break.

I made the decision as to how I was going to name each bookmark.

YOU have to make the same decisions.

How do you want each document "chunk" separated? A page break? A Section break? Perhaps with a little explanation text, like:

"The following is the text from yadda_hoha.doc.

[contents of yadda_hoha.doc]

"The following is the text from myDoc2.doc.

[contents of myDoc2.doc]

"The following is the text from YipeeKiYayMF.doc.

[contents of YipeeKiYayMF.doc]

"The following is the text from ClientHardwareRequests.doc.

[contents of ClientHardwareRequests.doc]

etc. etc.

And if you DID add some starting text (for each chunk/document), when you want to "pick out" any given chunk, do you want to include that starting text - or just the chunk contents alone?

How do you want to name each "chunk"? To be able to "pick out" an identified "chunk" it (if you use bookmarks), then it must have a name. Do you want to call each chunk - as you process through your 10 docs - say, "Doc1", "Doc2"...

Maybe name them by their filename? Part of their filename? Author? DateCreated? What?

These are logic decisions, and YOU have to make them. The actual coding to do what you seem to want is actually quite simple. Once the decisions are made as to WHAT you want to happen - EXACTLY what you want to happen - then coding it is pretty basic.

I (and others here) will be glad to help you with that, after you:

a) make your decisions as to what, exactly, you want to happen

b) try to do something yourself

I will say it again. The actual coding is not difficult. What is difficult is the understanding and thinking required to determine what coding is needed.

mangaluve
03-02-2009, 03:18 AM
Thanks for the long reply!

I don't really care much about how the document is divided into chunks, but it would be preferable if it didn't affect the document too much (at least to the eye). I got two things I'd like to try. First I'd like to use bookmarks for the different chunks. So I need to be able to pick out what is between two bookmarks.

The second choice would be to have a small header over each chunk, with the name of the chunk. For instance

[XXX]
some text and stuff
[YYY]
some other text and stuff

and then be able to extract the text by knowing XXX and YYY (so in my macro I have a list, with for instance XXX and YYY, and by chosing one of them, I want to extract the text). Hope it made sense! The names of the different chunks (header / bookmark name) doesn't matter much, those would be hard-coded and put into a list. So basically I'd like to divide a document into chunks (with bookmarks or headers) and I got all the bookmar/header names in my Form.

lucas
03-02-2009, 08:58 AM
Why not have all the data in one template file and select which ones to keep and delete the rest. This is a contribution by Gerry from previous posts but the attachments have been lost so I will post an example here.

Remember, this doc is just a doc. If you set it up as a template file, save it as a .dot file in other words, you can use it over and over.

The paragraphs are in bookmarks......they can be paragraphs, chunks, tables, anything really.

fumei
03-02-2009, 10:14 AM
Except, apparently, there are already 10 documents that the OP wishes to merge (sort of). But then, it is not clear.

"I don't really care much about how the document is divided into chunks,"

Well, if you do not care, then what is the point? To be able to have identifiable chunks, you need to care.

"First I'd like to use bookmarks for the different chunks. So I need to be able to pick out what is between two bookmarks."

VERY unclear. Why do you want to pick out what is between the chunks? if you are chunking differnt documents into one document...what is the stuff "between", and how did it get there?

However, if you actually really think about what you want to do (and you do not appear to have started to so that) getting the stuff between bookmarks is - just like the other things I have suggested - is fairly easy. You just have to (again) think it out as to what you actually want to do. The coding is not difficult.

"So basically I'd like to divide a document into chunks (with bookmarks or headers) and I got all the bookmar/header names in my Form."

Bookmarks or headers? Huh? These are utterly different things, and you clearly do not understand. I really wish I could help, but this is looking more and more hopeless.

Everything youi have mentioned (even if vaguely) is quite do-able.

lucas
03-02-2009, 10:49 AM
I agree Gerry, that's why I'm to the point of just throwing solutions at it until he finds a direction......

fumei
03-02-2009, 12:01 PM
You are a better man than I. I will not throw a solution until I figure what the solution is supposed to do!