Join files in Word v.X???

Hello,
I found a script here that purportedly worked in Word 2004, but it does not seem to work in Word v. X. I was wondering if anyone had any idea why. The idea was to create a script that joined multiple RTF files together into one file.

tell application “Microsoft Word”
set the_folder to choose folder “Choose your folder of RTF files”
set the_files to (my get_folder_list(the_folder, “rtf”))
set combineDoc to make new document
repeat with rtffile in the_files
open rtffile
set curDoc to the active document
select the text object of curDoc
copy object selection
close curDoc saving no
collapse range text object of combineDoc direction collapse end
paste object selection
end repeat
end tell

on get_folder_list(the_folder, file_extension)
set the_files to {}
tell application “Finder” to set folder_list to every file of folder the_folder whose name ends with file_extension
repeat with new_file in folder_list
copy (new_file as string) to end of the_files
end repeat
return the_files
end get_folder_list

When I try to save or run it, it highlights “document” after the word “active” (on line 7), and gives an error that says “expected and end of line, etc but found class name.” I have looked at the Word v. X dictionary, but do not see anything there that might preclude this from working. Any help is greatly appreciated.

I don’t have a copy of word with me so I can’t play with your code, but try setting this as a “reference to active document”. Just a thought.

Hi,

They added a lot of stuff in the newer version. Something like this seems to work in my Word X:

set the_folder to (choose folder)

tell application “Finder”
set file_list to every file of the_folder whose name extension is “rtf”
set alias_list to {}
repeat with this_file in file_list
set this_alias to (this_file as alias)
set end of alias_list to this_alias
end repeat
end tell

tell application “Microsoft Word”
launch
activate
set new_doc to (make new document)
repeat with this_doc in alias_list
open {this_doc}
select text of front document
copy
close front document saving no
select insertion point after text of front document
paste
end repeat
end tell

You can fix it up. Any question, ask.

gl,

Thanks a lot Kel…yours worked like a charm. And it’s shorter and more sensible than what I was working with. I got some catching up to do.

Thanks again.

Hi Bjorn,

You’re welcome.

After this line:

set file_list to every file of the_folder whose name extension is “rtf”

add this line:

if file_list is {} then return

gl,