[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.0

automating mail merge in Word with Excel data source

Asked by plymplan in AppleScript, Microsoft Word, Microsoft Excel Spreadsheet Software

Tags: applescript, excel, word, macintosh

I 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.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
tell application "System Events"
tell process "Microsoft Word"
keystroke "o" using command down
repeat until exists window "Open: Microsoft Word"
end repeat
set value of text field "search" of group 1 of window "Open: Microsoft Word" to "MyMailMerge.doc"
repeat until exists radio group 1 of group 1 of window "Open: Microsoft Word"
end repeat
try
tell UI element 2 of radio group 1 of group 1 of window "Open: Microsoft Word"
set {xPosition, yPosition} to position
set {xSize, ySize} to size
end tell
-- modify offsets if hot spot is not centered:
click at {xPosition + (xSize div 2), yPosition + (ySize div 2)}
end try
end tell
end tell
[+][-]06/18/09 01:57 PM, ID: 24661650Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: AppleScript, Microsoft Word, Microsoft Excel Spreadsheet Software
Tags: applescript, excel, word, macintosh
Sign Up Now!
Solution Provided By: plymplan
Participating Experts: 1
Solution Grade: A
 
[+][-]06/18/09 09:55 AM, ID: 24659343Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92 - Hierarchy / EE_QW_3_20080625