I have a document (called say C:\Main.doc ) which has several paragraphs. The first two words of the paragraph (which are always on the first line of the paragraph) are the first and the last names of a person about whom there is some information in the rest of the paragraph. I have a folder (C:\Important Document ) which contains separate files for all the those persons about whom there may be a paragraph in the Main.doc.
I would like to have a macro that will select the first two words of the first paragraph in the Main document. The macro should then check the folder (C:\Important Documents) to see if there is a file corresponding to the name of that person (there will always be such a file in that folder). On finding this file, the macro will open it, then the macro will select the whole of the first paragraph from Main.doc, cut it and past it into the open document. It will then save and close this document and then Select the first two words of the next paragraph (which was originally the 2nd paragraph but due to cutting and pasting in the previous step would now have become the first paragraph in the Main document. After selecting the first two letters the macro will repeat the process it did with the first paragraph. It will keep on doing this until all paragraphs from the main document have been cut out one by one and pasted into their respective files in the folder (C:\Important Documents\
To clarify this problem further as an example say my folder (C:\Important Documents) contains three files named Phillip Kaplan.doc John Martin.doc and Kim Slater.doc
Assuming that my Main.doc has three paragraphs as shown below. When the Macro runs it will first select the first paragraph and past it into the document called Phillip Kaplan.doc it will then cut 2nd Para and past it into John Martin.doc and lastly it will cut the 3rd Paragraph and paste it into Kim Slater.doc (the actual main Main.doc could have a lot more paragraphs like 30-40, and the actual total number of paragraphs in the Main.doc will vary from day to do, so the macro should basically keep on looping until it can find no paragraph in the Main.doc)
Contents of the Hypothetical Main.doc before the marco run will be as follows:
Phillip Kaplan:
Date of Visit: 18 June 2008
FBC: Leucocytosis.
Enzymes: Raised
John Martin:
Date of Visit: 18 June 2008
FBC: Leucocytosis.
Enzymes: Raised
Kim Slater:
Date of Visit: 18 June 2008
FBC: Leucocytosis.
Enzymes: Raised
And the Main.doc will be empty after the macro has run.
Many thanks in anticipation.
Open in new window