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



In VBA the only argument that can be specified with Presentations.Add is WithWindow that determines whether the new presentation is visible or not. There is no way to make an invisible presentation in AppleScript, since presentation does not have a visible property to set to false. (Its main document window does, but as with many applications, the visible property of document window is read-only, and is always true.) Nor is there any command such as hide. So invisibility is something you have to give up, if you were ever accustomed to making invisible presentations (for speed) in VBA.

At first there seem to be no properties of a presentation that you can set as such in AppleScript (the dictionary entry for presentation shows all properties as r/o: read only) but don't be dismayed – there are many properties, such as page setup, web options. slide show settings, etc. that return objects whose own properties can be set with abandon and almost infinite choices. This is similar in every Office app: it means you can set these 'properties of properties' after creation of the presentation but not in a 'make new' statement. There are also new elements that can be made at the presentation, also after creation of course, and then you can modify them (i.e. set the elements' own properties) as needed.

Don't forget that what VBA considers Properties includes many Collection Objects (such as Slides), which in AppleScript are elements that you make. All other properties of presentation, both in VBA and in AppleScript, are read-only, aside from a very few (east asian line break level, layout direction, and a few others) that the PowerPoint AppleScript Reference informs us are not available in U.S. English version of PowerPoint in any case. The one real gap in AppleScript, which somehow got omitted, is an equivalent to the DisplayComments property, which is a read/write property and should be controllable from AppleScript. You can make comments (in the Drawing Suite) and set all sorts of attributes for them, but not control whether they are visible or not.

So every script that needs to make a new presentation will start off, simply, as

tell application "Microsoft PowerPoint"

     set newPres to make new presentation

     tell slide 1 of newPres

          -- code here

     end tell

end tell

You must set a variable of your choice to the make new presentation statement, which by definition returns the object it has made, or you won't have anything to work with. Of course you won't always be going on to tell slide 1 (to set various properties of, and make new elements at, slide 1), but you will get around to that pretty soon in most cases. We will be looking into what can be done with presentations and slides in a moment.

Open an Existing Presentation

It's a relief to say that opening an existing presentation .ppt file is, as with all applications, dead simple in AppleScript. The equivalent of the Open method in VBA:

   Presentations.Open FileName:="Mac HD:Folder:Filename.ppt"

is the open command (in the Standard Suite) in AppleScript:

tell application "Microsoft PowerPoint"

     open alias "Mac HD:Folder:Filename.ppt"

end tell

Note that you should properly use the alias reference form, but the PowerPoint developers have enabled a coercion allowing you to use just the path text as an equivalent, just as in VBA. Also, in AppleScript, you can open a list of (presentation) files all at once if you wish. – just provide the list of .ppt aliases.

Sometimes we are interested not just in opening a presentation, but also in modifying it, or getting some information from it. In VBA, that is very straightforward: you just set a variable (reference) to the result of the Open statement, which returns a Presentation object, and then set some Properties of it or apply some Methods to it:

   Dim oPres As Presentation, oSlide As Slide

Set oPres = Presentations.Open(Mac HD:Folder:Filename.ppt")

With oPres

Set oSlide = .Slides.Add(2, ppLayoutText)

End With

The process of setting a variable to the result of a command is usually straightforward in AppleScript too. However, just as in Word, the command open from the Standard Suite does not return a result, so you cannot set a variable to the command. They would have done far better to do what Excel does – leave the plain open command in place for opening multiple files, and also give PPT its own 'open presentation' command with all the parameters, that does return a result.

Here is a workaround:

tell application "Microsoft PowerPoint"

     open "Mac HD:Users:yourname:Desktop:Saved Pres.ppt"

     set thePres to active presentation



< 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