PDA

View Full Version : Splitting a word doc into pages



davehants
06-27-2010, 07:36 AM
Hi,

I wonder if anyone can help me. I'm trying to split my large word doc into single pages and store each page as a new doc in the same folder, with the same file name with numbers appended (eg. origfilename001.doc).

I've seen examples in here that seem to do it if the page has delimiter characters - which are then removed in the output.

I don't want any character changes, just splitting by page.

Does anyone know if this is possible or have some sample code I could try?

Any help appreciated....

Regards,
Dave

Tinbendr
06-27-2010, 09:05 AM
Check out this Knowledge Base (http://www.vbaexpress.com/kb/getarticle.php?kb_id=727) entry.

davehants
06-27-2010, 12:21 PM
Many thanks for the link Tinbendr.

This looks a really good macro.

I've run it on my system (Win XP home SP3, Word 2003) against the sample file and it works. I've run it against my own file and it produces one single output file containing the complete input.

In other words, it doesn't seem to have recognised the 87 page breaks in my document.

I've switched on the option to see all formatting marks. And I can see a difference between the files - the sample file end of page says "Page Break" where as my file's end of page says "Section Break (Next Page)".

Any ideas how I can change the macro to recognise my page ends?

Any help appreciated....

Regards, Dave

davehants
06-27-2010, 12:32 PM
Each page starts with 5 characters (different ones in each doc) but they are in Arial 20 format. No other text in the page/s is in Arial 20. Would this help finding the right place for the macro to do the split if it can't recognise the strange page breaks?

Could the macro search on the these chars in this format to do the split?

Regards, Dave

Tinbendr
06-27-2010, 01:14 PM
Nothing is jumping out at me.

Try stepping through the code. Check iPageCount and see if it's reading the number of pages correctly.

Add
A = rngPage.End
rngPage.Collapse wdCollapseEnd 'go to the next page
A = rngPage.Startaround the collapse and see if the range is getting reset to 0. (Hover over each line and see what the number is. It should increment higher as it move through the document.)

Instead of Collapse, you may have to
rngPage.Start = rngPage.End + 1
Without a sample, I'm just guessing.

fumei
06-28-2010, 08:42 AM
Be clear. Sre you saying EVERY page is separated by a SectionBreak? Because if this is the case, doingat you want becomes much much easier.

davehants
06-28-2010, 02:58 PM
Yes, each page has "Section Break (Next Page)" at the end of it when I switch on "show all formatting" in --> File --> Options.

Good news hot off the press, I just found a macro at

gmayor.com/individual_merge_letters.htm

which does the trick.

It seems to change the font to correspond with my normal.dot, so I'm going to now investigate how to change that.

A while ago I tried to reset it to something else on my Word 2010 (beta) version (on my other system - Windows 7 64 bit) by following the MSFT instructions but I could never get it to work, so I'm going to see if I can do it on the old Word 2003 version....

I'll post results here....