PDA

View Full Version : Two macros: 1) Join RTFs 2) Split RTFs



sensesean
12-12-2011, 12:35 PM
Hi there,

I'm starting to get desperate after trying to learn how to code two macros for days now. My problem is that I very often need to combine many RTF/DOC files into one, do changes to this combined file, and then split the combined file back to the RTF/DOC files with the original file names. I simply lack the skills to code this.

Specifically I'd need two simple macros that would do the following, preferably in MS Word 2003:

1. JOIN ALL RTF FILES IN A FOLDER TO ONE COMBINED RTF FILE
- the macro would retain the layout of individual RTFs, possibly by storing each RTF file after a new section break in RTF
- the macro would also store the file name of each individual RTF to the joined RTF, with a <TITLE: originalfilename.rtf> tag (string) before the actual content. This info would be later used to split the combined RTF into original ones.

--- here I update the content of the combined RTF file, and then... ---

2. SPLIT THE COMBINED RTF FILE TO INDIVIDUAL FILES
- the opposite of the macro 1 above; this would save the combined RTF into splitted RTFs with the filenames stored in each <TITLE: originalfilename.rtf> tag.

BIG THANK YOU to anyone who might be able to help me out here!

Tinbendr
12-13-2011, 09:17 AM
You can use Master Document (http://www.youtube.com/watch?v=cu-WueVZ6n4). Make sure you make backups. Master Document has a way of corrupting files without warning.

sensesean
12-14-2011, 02:09 AM
Many thanks for the tip - just checked the video. Looks like this won't work for me, as what I need is automated macro with minimum of manual steps, as I need to process the docs very quickly. And corruption is something I must avoid at all costs, as it takes so much time to fix corruptions for a large set of files, say 150 of them. Combining the docs will have always some risk in it, but with a good macro I think I could manage the risk well enough.

I don't control the documents, as they come from various sources. Almost always they share identical styles, based on the same template. So far, I've created the combined doc by copy&paste, and inserted the filename tags manually to clearly show where to split the doc in the end.

I've created other macros that always process all the files in a fixed folder, so I could make use of that for this. I could always output the combined file to a fixed filename, like combined.rtf. What I could not figure out is how to write a macro that would do this:
1) read the name of the file that's currently active into a variable (like source_doc)
2) copy all the content of the active file to clipboard
3) make the combined.rtf active and go the last line
4) insert a section break (to prevent styles from getting mixed, if there are source doc-specific differences)
5) write the placeholder tag to contain the source_doc variable text (to store the original file name for later splitting and to show where the content came from to others) and a paragraph mark
6) paste all the content with everything (styles, layout, fonts+properties) right after the placeholder tag

If I can learn how to do this, then I'll be able to create the splitting macro (that will do the opposite) based on the combining macro.

That's the logic as far as I can see it. I don't know Word deep enough to know if this is a safe way to do this combining+splitting or whether there's more clever way to do this.