Share via

Loop thru Word document sections with AppleScript

Anonymous
2013-02-28T09:31:12+00:00

Hello,

I need some help with Word and AppleScript.

I have a long Word document that was built thru a mailing process.

I want to save each individual letters to a file.

So I need to loop thru de sections of my word document with AppleScript.

I dont't understand how to get the number of sections with the Word AppleScript dictionnary!

Can someone please help me?

Thanks.

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

5 answers

Sort by: Most helpful
  1. Anonymous
    2013-03-04T09:21:09+00:00

    Hi John,

    I work with Word 2011 in french!

    I tried to customize the ribbon to test your solution, but I have a problem.

    With the french version the commands are in the menu "Mode Plan" this menu is ticked to show-up in the ribbon but it doen's show up... I don't understand why!

    This is why I hate Word since version 2007. There is no logic in the user interface. The concept is: If the item is checked it shows up in the ribbon. So why is there some exceptions with: Mode Plan / Billet de blog / Insérer (billet de blog) / Suppression de l'arrière plan.

    Well, I will try to find a way around to test your solution. I will keep you updated!

    Thanks and best regards.

    Andrew

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2013-03-02T01:13:40+00:00

    I am sorry if i have made a mistake here, i am really new to this forum.

    John, I work for a small business, who thought that it would be better to use a few mac's. I found this out while looking for a solution to one of our issues.

    What i have seen elsewhere is that the the most recent updates are looked into first, so posting on something ideally moves it to the top of the queue.

    In case my understanding is wrong, i would surely stop doing that.

    Thanks anyways John for pointing that out.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2013-03-01T17:18:09+00:00

    Arshad:

    You DO know that once "Microsoft" answers, the MVPs won't even read the question.  You do know that, right?

    So if you post "I don't know" to a question, you are almost guaranteeing that the poster will never get an answer!  Could you please explain this to the other people in your workgroup?  The MVPs are fairly busy: if they see that Microsoft has answered, they won't bother to open the post, because they will assume that your answer will be correct.

    So please don't post if it isn't.

    Cheers

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2013-03-01T17:17:48+00:00

    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).

    1. Right-click the toolbar and choose Customise.
    2. Go to the Commands tab
    3. Select the All Commands category.
    4. In the Commands window, scroll down to the Create Subdocument command.
    5. Drag it to your toolbar.
    6. OK your way out.

    Now we need to do a little setting up in the output document.

    1. 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.
    2. 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.
    3. Open the mail merge output file in Word.
    4. On the View menu, change to Outline view.
    5. Select all of the text in the document (Command + a)
    6. Click the Create Subdocument button you just added to the toolbar.
    7. 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!

    Was this answer helpful?

    0 comments No comments
  5. Anonymous
    2013-03-01T02:03:18+00:00

    It would be best to check with Apple on the script part

    https://discussions.apple.com/index.jspa

    There are some MVP's here who are very good with that as well, so hopefully they would be able to help you out.

    Was this answer helpful?

    0 comments No comments