Andrew:
I would not do this in AppleScript. It is easy enough to do it in VBA, but I wouldn't do that either.
I would use the Word built-in Master Document feature. First, you need to customise the toolbar to restore a command that has been left out (the entire Master Document feature has been left of the toolbars, but it's still there, and it's very powerful).
- Right-click the toolbar and choose Customise.
- Go to the Commands tab
- Select the All Commands category.
- In the Commands window, scroll down to the Create Subdocument command.
- Drag it to your toolbar.
- OK your way out.
Now we need to do a little setting up in the output document.
- Make sure that each "Letter" begins with a paragraph formatted with the Heading 1 built-in style. You can change the format of the style to suit your purposes, but make sure that each letter begins with a Heading 1 style, because that's what Word will
use to divide the letter.
- Word will use the first characters in the Heading 1 line (up to the first space or non-alphabetic character) as the file name for each of the individual files. So make the first line unique to each letter. I would make the first line the recipient's name
and initials with no spaces. You can set up the mail merge to do this for you automatically.
- Open the mail merge output file in Word.
- On the View menu, change to Outline view.
- Select all of the text in the document (Command + a)
- Click the Create Subdocument button you just added to the toolbar.
- Save the document.
You will see the folder that contained the mail merge output document magically fill up with letters, the file name of each one is the text from the Heading 1 paragraph (the name of the recipient).
There you go: the whole job is done in two clicks! No coding at all. And now it is set up, it will work every time on any output document. Obviously, you would set up the mail merge to insert the recipient line at the top of each letter, and you would
set up your mail merge main document to have the Heading 1 format on that line.
You do not have to use Heading 1 as the style, but it must be one of the built-in Heading series of styles, and Word will split the letters at the highest Heading style it finds, so make it Heading 1 to save complexity. As I said: change the formatting
of Heading 1 style to suit.
Hope this helps!