Hi,
This question might be more suited to the developer forum, but I figure it's not too out of place here and may get a slightly wider audience. I'm an experienced software developer (mostly Java and a bunch of Cocoa) but I know very little about AppleScript or Microsoft Office. Please excuse any errors in the terminology I use.
I'm trying to figure out how to go through a Microsoft Word file (probably a template .dotx, actually, but whatever) and replace certain pre-determined "fields" with user-supplied data. Kind of like a mail merge, I guess, but ideally I'd like to pop up a dialog that the user can fill out, press "OK" and have all the relevant portions of the document be replaced appropriately.
The version of Word is 2008, so from the cursory amount of research I've done it seems like AppleScript Studio is what I want to be using - Interface Builder to create a fancy dialog and AppleScript to talk to Word to actually go through and replace the placeholder data.
(Is "AppleScript Studio" just a blanket term for somehow being able to combine Interface Builder nibs with AppleScript? Obviously I need to look into this more.)
Anyway, to summarize the basic workflow I have in mind:
- The user opens MyFile.dotx, so a pre-cooked document opens as "Document1"
- The user opens the (e.g.) "Enter Data" script from the scripting menu
- A dialog opens up with various text fields, drop-down lists, etc. that does some validation (like makes sure all required fields have been filled out) before the user can click the "Populate" button
- The appropriate placeholders in Document1 are updated with the data the user entered in the dialog
- Bonus points if the document can get saved to a pre-determined (likely read in from a config file or something?) location based on something the user entered in the dialog
This seems like a reasonably common use case, so I'm hoping someone here has done something like this before and can point me in the right direction. Obviously I need to familiarize myself with AppleScript in general, but I'm clueless about which commands I should be trying to send ("tell"?) Office, and especially how I should structure the .dotx template such that there are portions of the document I can identify via AppleScript and update with the data.
To tell the truth at this point I don't even know how to go about making a fancy dialog that I can open from an AppleScript, but Google has found me a couple tutorials so I don't think that'll be too tough to get going.
Thanks in advance for any help!
-parsec