• 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 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.



< 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