Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Automate Microsoft Word using AppleScript and VBA Apps
In order to put together a small book for the kids' elementary school, I had to find a way to automate Microsoft Word to build web pages. I know people in the publishing industry do this frequently with QuarkXPress and AppleScript, and when I saw that Word for OS X had AppleScript support, I figured it would be a snap.

However, I'm not a great scripter, and when I when searching on the web for examples showing how to script Word, I couldn't find much at all. What I did discover is that Word has a reputation for problems with AppleScript. Whether or not that's true, there certainly is a dearth of good examples for using AppleScript with Word. Of course, Word comes with its own scripting language, VBA. This is incredibly popular in the Windows world for scripting Word (and Excel, and other Office apps), but the Mac version of Word also supports it. But since I've never worked in VBA at all, I was nervous about trying to do my project exclusively using VBA.

Then I discovered you can actually use both technologies together -- and AppleScript can send VBA commands to Word, one at a time. And there is tons of VBA information to be had on the web. Anyway, here's a sample AppleScript that shows how to use AppleScript and VBA together to put together a Word web page. I'm no AppleScript expert, and I've never used VBA before, but if you're a beginner, too, maybe you can find something useful here!

[robg adds: Due to the width of some of the lines, I chose to upload the script. The above link should open it in a new window, ready for a quick copy and paste.]
    •    
  • Currently 2.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
 
[5,964 views]  

Automate Microsoft Word using AppleScript and VBA | 3 comments | Create New Account
Click here to return to the 'Automate Microsoft Word using AppleScript and VBA' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Automate Microsoft Word using AppleScript and VBA
Authored by: petey on Jun 28, '04 08:28:10PM
"What I did discover is that Word has a reputation for problems with AppleScript."

Prior to the release of Microsoft Word '04, there really wasn't much of an AppleScript implementation at all. The current AppleScript implementation is new from the ground up in Word '04.

It should be possible to do much, if not all, of the work of your script in pure AppleScript as of now. But since the AppleScript implementation is new, you won't find the kind of pre-made examples on the web that you will for VBA.

[ Reply to This | # ]

Automate Microsoft Word using AppleScript and VBA
Authored by: Jon on Jul 08, '04 07:17:05AM

Well, for me ANY Applescript with the "do visual basic"-command fails! I always get the error message "Ambigous name was detected: TmpDDE" (or something like that - that was my translation from Swedish) - and the Applescript executing stops.

This happens in various versions of Word, up to Office X.
One strange thing is that I can use the record-function in Applescript in OS 9. This creates a Script with "do Visual Basic"-commands, and the script compiles fine. Still I get that error-message from Word when running the script!

Do anyone happen to know what this is all about?



[ Reply to This | # ]
Automate Microsoft Word using AppleScript and VBA
Authored by: stevie02476 on Jul 08, '04 03:23:17PM
One thing I didn't mention in my submitted hint about Automating Word using AppleScript and Visual Basic, and should have, is what versions of things I was using. Here's my system, hardly the latest 'n greatest!

  • Mac OS X 10.2.8
  • Script Editor v1.9
  • Microsoft Word vX (v10.0.0 - 1316) from 2001!

    I truly don't know what effect using a newer version of any of these would have on my script. Also, I think Word has a lot of possible security settings (ranging from "risky" to "dangerous" I guess :) ) and I'm sure it's possible to have Visual Basic turned off or not even available. Good luck to everyone who goes down this path.

    [ Reply to This | # ]