Has anyone scripted with Word before? I’m not finding the dictionary to be particularly helpful, and when I try recording actions, they’re all just Visual Basic commands, which I DO NOT know. Basically, I want to make a new paragraph/font style, and apply it to the whole text. There’s more to do after that, but if I can get that going, I’ll be off to a good start. Thanks for any help.
I am in a similar situation. I downloaded the Word 2004 AppleScript Reference and that helps some, but I find quite a few concepts that are not made clear. I’m trying to get a handle on this, too, and would appreciate anyone pointing to a tuorial resource on scripting Word.
I have done some Word scripting, and yes, it is not nearly as intuitive as scripting other apps, but with some trial and error (based on copying code straight from Microsoft’s AppleScript Documentation) I have been able to accomplish nearly everything that I need to do. Based on what sort of paragraph or font styles you need to manage, this may help get you started:
set the_text to "Hello World" tell application "Microsoft Word" set newDoc to make new document insert text the_text at end of text object of newDoc set name of font object of text object of newDoc to "Arial" --Changes the font. set font size of font object of text object of newDoc to 18 --Changes the font size end tell
As my schedule permits, I am happy to help in any way I can. I know that there are others in this forum as well that are experienced Word scripters. Try to be specific about what you are looking to solve, and post any code you have tried (regardless of how it worked, or not) and you stand the best chance of receiving helpful replies.
I can’t speak to Word specifically, but is it watchable/recordable like Excel is? If so, you can get alot out of it by recording yourself doing it once with Script Editor.
Neither Word nor Excel (2004 versions) are AppleScript recordable in Script Editor; is there another editor out there that can record these applications?
Ah didn’t see a version referred to in the original post. I didn’t assume 2004 was being used because the old 2004 AppleScript guides are all there are, I haven’t seen newer ones for the new versions.
I know Excel 10.1.4 is Recordable (it’s what I have now, under Tiger), as is the couple of versions before that, at least back as far as some version we had in late 2004 (but whether it was “Office 2004” or not I can no longer say…wasn’t really paying attention). I’ve been recording Office X for a while (since Jaguar), but if we’re talking Office for pre-OS X, then apologies for my confusion.
One other way you can do it takes a bit more programming know-how, but…
If Word 2004 has a macro editor (basically VBScript-based near as I can tell in Office X), it may be able to record. If so, have it record. The syntax is not the same as AppleScript, but I have pried-out parameters and single commands this way for things AppleScript couldn’t record. In Office X, the VB commands and parameters and their AppleScript equivalents are 1-to-1 or “almost” 1-to-1 in many cases.
Just a thought, and again my apologies for the version confusion.
(Can someone clarify via Get Info what “version” Word for Office 2004 is? Like I said, Word for Office X on our current Tiger build is Word 10.1.4)
Right, should have thought of that. The current Excel 2004 is version 11.2.5 and Word 2004 is 11.2. They both have the ability to record macros for repetitive actions.
Wait, so you’re saying “Office 2004” is newer than “Office X”?
Not to threadjack, but I’m confused, and I’d like to get it straightened out before I confuse anyone else with my “advice.”
If you try using the built-in Macro record, then use the editor to see the Macro code, that may give clues as to how AppleScript commands might work, and what parameters, and values, the command might take. I had good luck doing this, but then again I’ve done my fair share of programming in the past. I find alot of programming languages seem “alike.”
(Well, I don’t miss line-BASIC and line-CP/M, but that’d date me a bit…DOH!)