AppleScript to Combine Several .doc Files

S

Sam Elowitch

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

-Sam
 
P

Paul Berkowitz

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

Paul Berkowitz

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

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

Fredrik Wahlgren

Re: AppleScript to Combine Several .doc FilesMy God.. Awesome!! Imagine how much work this would require on a PC!

/ Fredrik
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.
 
P

Paul Berkowitz

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 <[email protected]>
Newsgroups: microsoft.public.mac.office.word
Date: Sat, 18 Sep 2004 19:39:23 +0200
Subject: Re: AppleScript to Combine Several .doc Files

My God.. Awesome!! Imagine how much work this would require on a PC!

/ Fredrik
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top