Thanks but the question specifically addresses Macintosh environment. We were able to automate the mail merge on the Windows side with just VBA.
Main Topics
Browse All TopicsI have a Microsoft Word document that is a mail merge, with an Excel workbook as the data source. I'm trying to automate the opening of this document. This seems like such a basic request, and there ought to be a way to do it, but I've tried many things without success. Any help would be appreciated. I'm running Mac OS X 10.4.11, Word 2004 11.5.3 and Excel 2004 11.5.4.
When I open the document directly from Word, I get an "Open Workbook" dialog, asking for two things: the worksheet to be used as the data source, and the cell range. The AppleScript needs to be able to get through this dialog automatically, without the user having to do any clicking.
My first attempt was this:
tell application "Microsoft Word" to open file name "MyMailMerge.doc"
But when I do this, the "Open Workbook" dialog still appears, just as if I had opened it directly from Word. The AppleScript hangs on the above command until the user manually selects the worksheet and cell range, so there is no opportunity for the script to negotiate the dialog through GUI scripting.
So it seems I need to do the whole thing through GUI scripting. But with GUI scripting, I'm not even able to get through the "Open: Microsoft Word" dialog. Below is my attempt, with some extraneous detail removed:
SEE CODE BELOW
The goal of the "click at" command is to click the UI element marked "Computer", so that it searches the entire computer for the file "MyMailMerge.doc". I know I'm getting the right UI element, because if I display the variables xPosition, yPosition, xSize and ySize, they are the right values, as shown by the UI Browser in Screen Reader mode when I hover over that UI element.
But the "click at" command has no effect. Another choice (Folder "xxx") remains selected, so the script cannot proceed. If I manually click on "Computer", it works fine.
Any help would be appreciated. It really shouldn't be this hard to automate a mail merge.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: JOrzechPosted on 2009-06-18 at 09:55:39ID: 24659343
I'm just going to toss out a few things here since you haven't received a response. I take it you don't want the confirmation of the data source to open... that's one issue right?
Is Excel set up as a datasource option under Control Panel, Administrative Tools, User Data Sources?
Also, check in Windows Explorer, Folder Options, File Types, Excel (XLS), Advanced, and change your settings to be like the image I uploaded. See if that helps.
I fear I probably won't be able to assist you with the rest of your question...
Options