MacTech Network:   MacForge.net  |  Computer Memory  |  Register Domains  |  Printer Supplies  |  Cables  |  iPod Deals  |  Mac Deals  |  Mac Book Shelf


  MacTech Magazine

The journal of Macintosh technology

 
 
BetterRam.com

Magazine In Print
  About MacTech  
  Home Page  
  Subscribe  
  Archives DVD  
  Submit News  
  Submit a Tip!  
  Get a copy of MacTech RISK FREE  
Google
Entire Web
mactech.com
Mac Community
More...
MacTech Central
  by Category  
  by Company  
  by Product  
MacTech News
  MacTech News  
  Previous News  
  MacTech RSS  
Article Archives
  Show Indices  
  by Volume  
  by Author  
  Source Code FTP  
Inside MacTech
  Writer's Kit  
  Editorial Staff  
  Editorial Calendar  
  Back Issues  
  Advertising  
Contact Us
  Customer Service  
  MacTech Store  
  Legal/Disclaimers  
  Webmaster Feedback  

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 107



     set allDocProps to every document property of active presentation

     repeat with i from 1 to count allDocProps

          set theDocProp to item i of allDocProps

          set theLog to theLog & "Property Number: " & i & return

          set theLog to theLog & "Property Name: " & name of theDocProp & return

          set theLog to theLog & "Property Value: " & value of theDocProp & return

     end repeat

     set theLog to theLog & "END =========================" & return

end tell

theLog

Note that document property refers just to the built-in ones, although there's no "built in" in the name of the AppleScript class. Since, in AppleScript, document property is an element of the application, every document property gets all of them. (There appear to be 30.) This class is found in the Microsoft Office Suite, in all the Office applications. Adding some Custom properties in the UI does not add them to every document property. It should add them to the separate list of custom document properties. However, trying every custom document property does not get them either. That's a bug.

Once you know the name of the property you're looking for, you can work with it. To display the value of a particular DocumentProperty, Template for example, in VBA:

With ActivePresentation

MsgBox .BuiltInDocumentProperties("Template").Value

End With

The AppleScript equivalent is:

tell application "Microsoft PowerPoint"

     set templateValue to get value of document property ¬

          "Template" of active presentation

     if templateValue ­ missing value then

          display dialog templateValue

     else

          display dialog "There is no Template: this presentation is " & ¬

              "based on a Blank New Presentation" with icon 2

     end if

end tell

The template property value seems to be missing value (i.e., doesn't exist) whenever your presentation is not based on a template you have created or imported into your My Templates folder (or a subfolder of Templates folder) by selecting it in the Project Gallery. This is true also in VBA, but there you get a blank MsgBox. In AppleScript, you get an error message, so it's nicer to trap the error and provide a better message dialog.

"Template" is a read-only property; you can't change it. Other properties like "Author" are read/write. To change the value of a read/write property in VBA, you'd do:

With ActivePresentation

.BuiltInDocumentProperties("Author") = "Your Name Here"

End With

It should have your name by default already (all Office applications know to look in the Entourage Address Book for the "Me" contact and use your name there for the Author document property.) But if you want a fancier version, say for business purposes, here's the AppleScript you could run on every commercial presentation you make and send out:

tell application "Microsoft PowerPoint"

     set value of document property "Author" of active presentation to ¬

          "Joe Blow, King of the World"

end tell

In the UI, go now to File/Properties/Summary, and you'll see it there loud and clear. (Don't worry, you can change it back…)

In Summary

You need to constantly compare the VBA Objects, Properties, and Methods to the classes, properties, elements, and commands in the AppleScript dictionary to try to work out which are equivalent. You can only do that now, in Office 2004, since the VB Editor will not exist in Office 2008. Your job is much harder in PowerPoint than in Word and Excel, since the PowerPoint dictionary seems to be missing a good third or so of the classes and properties you may need. But if you think creatively, you will often find workarounds. Of course, there's always the next version to look forward to, where hopefully many of these gaps will be filled.



 


Click here to find out more about our best subscription bundle deal ever!
2 years of the magazine, and the all new MacTech DVD ... at 70% off!



Click on the cover to
see this month's issue!

TRIAL SUBSCRIPTION
Get a RISK-FREE subscription to the only technical Mac magazine!
 
 


MacTech Magazine. www.mactech.com
Toll Free 877-MACTECH, Outside US/Canada: 805-494-9797

Register Low Cost (ok dirt cheap!) Domain Names in the MacTech Domain Store. As low as $1.99!
Save on brand compatible and name brank ink jet and laser supplies.
Save on long distance * Upgrade your Computer
Movies with No Late Fees!

See local info about Westlake Village
SJ * BRJ * BJ * OJ * NITS
Staff Site Links



All contents are Copyright 1984-2008 by Xplain Corporation. All rights reserved.

MacTech is a registered trademark of Xplain Corporation. Xplain, Video Depot, Movie Depot, Palm OS Depot, Explain It, MacDev, MacDev-1, THINK Reference, NetProfessional, NetProLive, JavaTech, WebTech, BeTech, LinuxTech, Apple Expo, MacTech Central 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.