Merging Word Docs w/ Applescript

I'm writing a MS Word document with contributions from multiple authors and editors. I'm new the Applescript but I have invested a couple of days now trying to figure out how to create an application that would merge multiple word documents together. I'm using Microsoft Word for Mac Version 15.15 on a Mid 2011 iMac running OS X El Capitan 10.11.12. I'm hung up on how to use the merge command in the Script Editor. Starting with just two documents, I'm writing things like:


tellapplication "Microsoft Word"

openfile name ((path todesktop folder) & "TestingMerge.docx") asstring

set myMerge to merge file name ((path to desktop folder) & "TestingMerge2.docx") as string

end tell


I keep getting an error:

Result:

error "Microsoft Word got an error: Can’t continue merge." number -1708


I'm done many variations on this general theme, but just don't know how to use the merge command correctly or there is some weird bug that has broken this command. I've looked everywhere for applescript code from anybody that has used the merge command to see how the syntax and format is supposed to look, but I haven't found anything.


Any help would be much appreciated.

iMac, OS X El Capitan (10.11.2)

Posted on Jan 8, 2016 6:21 PM

Reply
5 replies

Jan 8, 2016 7:37 PM in response to Botchweys

Hello,


You must specify an opened document and a file path with the merge command.


In Applescript's dictionary of Microsoft Word:

mergev : Merges the changes marked with revision marks from one document to another.

merge document

file name text : The file path and name of the document to merge with this document.


set file1 to (path to desktop folder as text) & "TestingMerge.docx"

set file2 to (path to desktop folder as text) & "TestingMerge2.docx"

tell application "Microsoft Word"

set thisDoc1 to openfile namefile1

mergethisDoc1file namefile2

end tell

Jan 10, 2016 5:56 PM in response to Botchweys

Botchweys wrote:


How do I refer to the merge output in a new command? Ι want to save the merge output under the name of the original file.


Something like this:


set file1 to (path to desktop folder as text) & "TestingMerge.docx"

set file2 to (path to desktop folder as text) & "TestingMerge2.docx"

tell application "Microsoft Word"

set thisDoc1 to open file name file1

set {folderPath, tName} to {path, name} of thisDoc1

-- remove name extension and append "3.docx" to the name

set newName to (text 1 thru -6 of tName) & "3.docx"


mergethisDoc1file namefile2

-- the new document (merge output) is the frontmost document

save (active document) in (folderPath & ":" & newName)

end tell

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Merging Word Docs w/ Applescript

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.