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


  MacTech Magazine

The journal of Macintosh technology

 
 

Magazine In Print
  About MacTech  
  Home Page  
  Subscribe  
  Archives DVD  
  Submit News  
  MacTech Forums  
  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 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



 


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!
 
Nokia Qt Beta
 


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.