Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

AppleScript to Combine Several .doc Files

186 views
Skip to first unread message

Sam Elowitch

unread,
Sep 15, 2004, 5:51:34 PM9/15/04
to
Is there an AppleScript that sequentially combines a folder full of Word
docs into a single document?

-Sam

Paul Berkowitz

unread,
Sep 15, 2004, 11:35:15 PM9/15/04
to
On 9/15/04 2:51 PM, in article BD6E31A6.EDBC%selo...@gwi.net, "Sam Elowitch" <selo...@gwi.net> wrote:

> Is there an AppleScript that sequentially combines a folder full of Word
> docs into a single document?


1. Copy and paste the following script into Script Editor (/Applications/AppleScript/).
2. Save it (named "Combine Word Docs") as an Application, anywhere convenient. You can drag it into the dock if you wish.
3, Re-name - or make copies of your docs and rename the copies - so that they appear in list or column view in the order in which you wish to combine them (i.e. alphabetical order).
4. Command-click or shift-click all the documents you wish to combine to select them all.
5. Drag them onto the applet you saved ("Combine Word Docs").
6. The combined doc will be open in Word. Name it and save it in the usual manner.



on open theFiles
   
    tell application "Microsoft Word" to set comboDoc to make new document
   
    repeat with i from 1 to (count theFiles)
        set theFile to item i of theFiles
       set filePath to theFile as Unicode text
       tell application "Finder"
            set {creaType, fileType} to {creator type, file type} of theFile
           set ext to name extension of theFile
           set fileName to name of theFile
       end tell
       if (creaType is "MSWD" and {fileType} is in {"BINA", "W8BN", "s8BN", "W6BN", "s6BN", "RTF "}) or ext = "doc" then
           tell application "Microsoft Word"
                set comboRange to text object of comboDoc
               set collapsedRange to collapse range comboRange direction collapse end
               insert file file name filePath at collapsedRange
           end tell
       end if
   end repeat
   tell application "Microsoft Word" to activate
end
open



--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be ignored.

PLEASE always state which version of Microsoft Office you are using - **2004**, X  or 2001. It's often impossible to answer your questions otherwise.

Paul Berkowitz

unread,
Sep 15, 2004, 11:45:07 PM9/15/04
to
On 9/15/04 8:35 PM, I wrote:

          3, Re-name - or make copies of your docs and rename the copies - so that they appear in
          list or column view in the order in which you wish to combine them (i.e. alphabetical
          order).


The simple way to do that would be to prefix "01 " "02 ", "03 " etc. to the names of the duplicated files. (If the files are all in the same folder to begin with, just duplicate the folder and use the files in the duplicated folder, prefixing the names by these numerals. That would be the simplest.)

Sam Elowitch

unread,
Sep 18, 2004, 12:29:21 PM9/18/04
to
Omigod. Berkowitz, you da man. I don't know how you do it. :-)

-Sam

On 9/15/04 11:35 PM, in article BD6E5803.73C7F%berkowit@spoof_silcom.com,

Fredrik Wahlgren

unread,
Sep 18, 2004, 1:39:23 PM9/18/04
to
My God..  Awesome!! Imagine how much work this would require on a PC!
 
/ Fredrik

Paul Berkowitz

unread,
Sep 18, 2004, 8:02:59 PM9/18/04
to
Thank you. The combining part would be just the same on a PC, using Visual Basic. But choosing which docs to combine would be trickier. The fact that AppleScript can script the Finder, inspect the files, and especially lets you drag the files onto an applet is a real advantage. Using just VBA in Word itself - on a PC or Mac - would probably mean you'd have to close all other documents, open just the ones you wanted to combine, and carefully layer them in the order you wanted.


--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be ignored.

PLEASE always state which version of Microsoft Office you are using - **2004**, X  or 2001. It's often impossible to answer your questions otherwise.



From: Fredrik Wahlgren <fredrik.p...@mailbox.swipnet.se>
Newsgroups: microsoft.public.mac.office.word
Date: Sat, 18 Sep 2004 19:39:23 +0200
Subject: Re: AppleScript to Combine Several .doc Files

goo...@dogearpublishing.net

unread,
Apr 5, 2017, 9:14:22 AM4/5/17
to
Not to necro this thread but I just found this and this is super helpful! When I run the script it ask for permission for every word file. Is there a way around this?
0 new messages