• MacTech Network:
  • Tech Support
  • |
  • MacForge.net
  • |
  • Apple News
  • |
  • Register Domains
  • |
  • SSL Certificates
  • |
  • iPod Deals
  • |
  • Mac Deals
  • |
  • Mac Book Shelf

MAC TECH

  • Home
  • Magazine
    • About MacTech in Print
    • Issue Table of Contents
    • Subscribe
    • Risk Free Sample
    • Back Issues
    • MacTech DVD
  • Archives
    • MacTech Print Archives
    • MacMod
    • MacTutor
    • FrameWorks
    • develop
  • Forums
  • News
    • MacTech News
    • MacTech Blog
    • MacTech Reviews and KoolTools
    • Whitepapers, Screencasts, Videos and Books
    • News Scanner
    • Rumors Scanner
    • Documentation Scanner
    • Submit News or PR
    • MacTech News List
  • Store
  • Apple Expo
    • by Category
    • by Company
    • by Product
  • Job Board
  • Editorial
    • Submit News or PR
    • Writer's Kit
    • Editorial Staff
    • Editorial Calendar
  • Advertising
    • Benefits of MacTech
    • Mechanicals and Submission
    • Dates and Deadlines
    • Submit Apple Expo Entry
  • User
    • Register for Ongoing Raffles
    • Register new user
    • Edit User Settings
    • Logout
  • Contact
    • Customer Service
    • Webmaster Feedback
    • Submit News or PR
    • Suggest an article
  • Connect Tools
    • MacTech Live Podcast
    • RSS Feeds
    • Twitter

Moving from Microsoft Office VBA to AppleScript:
MacTech's Guide to Making the Transition

Introduction  |  Table of Contents

Page Prev and Page Next buttons at bottom of the page.

Would you like a hard copy
or PDF of this Guide?

You can get a hard copy sent to you
AND download a PDF now ($19.95)
, or

... just download a PDF ($9.95).

Either way, you get a complimentary
MacTech Magazine Subscription

courtesy of the
Microsoft Mac Business Unit


 

  Magazine Reg. Price:  $50.00 value  
  Guide Reg. Price:  $40.00 value  
  You Save:  over $80.00!  

April, 2007
Page 3



Another example:

   temp = Options.DefaultFilePath(wdUserTemplatesPath)

in VBA becomes in AppleScript:

set temp to get default file path file path type user templates path

(Note in the latter example a departure from the VBA model where DefaultFilePath is a Property of the Options object while in AppleScript get default file path is a command with a file path type parameter, and user templates path one of the enumerated values it can have.)

Regular AppleScripters can be put off by these long run-on constructions found in Office 2004 scripting: there‘s nothing very English-like about it, without the usual prepositions at the beginning of parameter names (or else "–ing" participles on verbs) that would improve readability. At times, the enumerated values repeat words found in the parameter names, which in turn may repeat words found in the command name, and they seem to run together. Regular VBA scripters will be pleased to see familiar terms appearing in the AppleScript version, and will soon adapt to the lack of dots and other punctuation. Most writers of Office VBA macros should become accustomed to Office AppleScript quite easily.

Dictionaries

So, where are these Word-specific AppleScript terms to be found? Don‘t go looking in the Help menu, as you might in the VB Editor. Script Editor‘s Help knows nothing about Word or Excel or any of the hundreds of other scriptable applications. Look in the File menu of the Script Editor, at the "Open Dictionary…" menu item. Select "Microsoft Word" in the list that comes up (or click the Browse button if you can‘t find it, and browse to it in /Applications/Microsoft Office 2004/ via a normal Mac OS "Open" navigation box).

You will now see the Word AppleScript Dictionary, with the hundreds of classes and commands available. They are divided into Suites of associated terms: don‘t forget to check more than one suite (you‘ll usually start with the Microsoft Word Suite) if you don‘t find what you‘re looking for.

In particular, always remember that text range – corresponding to Range Object in VBA – is a class in the Text Suite. (But in Excel, the range class is in the Table Suite. Go figure.) Or if you have a good idea at what the term you‘re looking for, or part of the term, might be called in AppleScriptese, just enter it in the Search box and look through the results.

You‘ll soon figure out the color-coded "C", "P" and other icons for "Command", "Class", "Property", etc. also spelled out in the Kind column. (If you‘re treating yourself well and have Script Debugger, there are more results including "F" for Functions, i.e., Commands returning results, "#" for enumerations, and so on, and clearer descriptors.)

The Dictionary entries show you all the properties and elements of classes, e.g.,

footnote n [inh. base object] : Every footnote

 

elements

contained by documents, selection objects, ranges.

 

properties

entry index (integer, r/o) : Returns the index for the position of the object in its container element list.

note reference (text range, r/o) : Returns a text range object that represents a footnote mark.

text object (text range, r/o) : Returns a text range object that represents the portion of a document that's contained in the footnote object.      

The current version of Script Editor shows you which classes the class in question is an element of – i.e., is contained by – as well as any elements it itself may contain – here none. For those who can afford to splurge (or check the Demo), Script Debugger makes the hierarchy clearer. Note that the description of each property begins with the data type of the property, e.g., integer (a basic AppleScript type), text range (another Word class), and so on. Other classes, such as text range here are clickable links to their own entries in the Dictionary, which is useful.

If the properties are read only, they are marked as r/o. (Tip: some r/o properties can actually be set at the time of creation only, when using the 'make new [object] with properties {…}' command. In other words, it‘s always worth a try to see if it‘s possible.) When making a new object, there are default values for every property, so they do not have to mention it if default. The dictionary will usually, but not always, tell you what the defaults are, especially for boolean properties (true or false values).

For commands, the Dictionary shows you any parameters and whether a result is returned or not:

undo v : Undoes the last action or a sequence of actions, which are displayed in the undo list. Returns true if the actions were successfully undone.

 

undo document



< Previous Page Next Page>
 
MacTech Only Search:
Community Search:

 
 
 

 
 
 
 
 
  • SPREAD THE WORD:
  • Slashdot
  • Digg
  • Del.icio.us
  • Reddit
  • Newsvine
  • Generate a short URL for this page:



MacTech Magazine. www.mactech.com
Toll Free 877-MACTECH, Outside US/Canada: 805-494-9797
MacTech is a registered trademark of Xplain Corporation. Xplain, "The journal of Apple technology", Apple Expo, Explain It, MacDev, MacDev-1, THINK Reference, NetProfessional, Apple Expo, MacTech Central, MacTech Domains, MacNews, MacForge, and the MacTutorMan are trademarks or service marks of Xplain Corporation. Sprocket is a registered trademark of eSprocket Corporation. Other trademarks and copyrights appearing in this printing or software remain the property of their respective holders.
All contents are Copyright 1984-2010 by Xplain Corporation. All rights reserved. Theme designed by Icreon.
 
Nov. 20: Take Control of Syncing Data in Sow Leopard' released
Nov. 19: Cocktail 4.5 (Leopard Edition) released
Nov. 19: macProVideo offers new Cubase tutorials
Nov. 18: S Stardom anounces Safe Capsule, a companion piece for Apple's
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live