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

 
 
MacSpeech Dictate

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 106



    

     --no 'master' property of slide, get slide master of presentation

     set theMaster to slide master of active presentation

     make new shape at theMaster with properties {auto shape type

          autoshape rectangle, left position:10, top:20, width:30, height:40}

    

end tell

Remember that you need to click anywhere in the Slide pane, if you're in Normal view, to make it active (have the focus) before you run the script, since slide of view doesn't exist, and will cause the next line to error otherwise. If you specify a slide other than by selection, this is not an issue, of course.

Now there's a new problem: The dictionary has no master property of slide class corresponding to the .Master you see in VBA. (Honestly, I don't know what they were up to.) However the master of any slide in a presentation is the same as the slide master property of the presentation — which, fortunately, we do have. Obviously, the presentation of the selected slide (there's no actual property for that either) has to be the active presentation – otherwise it couldn't be selected.

If you look up the VBE Help for Shape (you probably knew this already), you will see that the AddShapes Method adds an AutoShape, specified by a particular MsoAutoShapeType constant, plus four integers to describe its position and size: Left, Top, Width, Height. That's what the VBA code above is specifying.

In the shape entry in the dictionary (Drawing Suite), you will find an auto shape type property, which is read/write. Taking a look at it (click the link of its 'type', also auto shape type), you see a long enumerated list of constants that looks very similar to the MsoAutoShapeType enumerated contacts in the VBE Help and Object Browser. Furthermore, it includes an autoshape rectangle constant. Meanwhile the separate shape type enumerated property of shape class has nothing equivalent – nothing that even mentions rectangle. So it's pretty clear that auto shape type enumeration is the one you want, in particular the autoshape rectangle constant.

For the other properties needed for make new shape, it's obvious that left position, top, width and height are the ones you want, Try them out. The script works perfectly. Now insert a new slide: the same rectangle appears. You have been successful in adding a shape to the slide master.

You may be aware that you can have multiple masters, called Designs, in the UI of PowerPoint 2004 (and later). (Check the Help for more information.) On Windows, the Designs Collection has been incorporated in PowerPoint VBA since PPT 2002 – that's three versions now. Unfortunately, it has never made it into PowerPoint Mac. Since the AppleScript model is (with some significant gaps, as we have seen) a port of the VBA Mac Model, it's not in AppleScript either.

What you can do is apply a Design to a presentation from a template by using the apply template command, equivalent to the ActivePresentation.ApplyTemplate (FileName) method in VBA. If the template (represented by the file name parameter) has multiple designs then presumably they will get applied: you just can't verify afterwards the Designs you now have.

If you receive some PowerPoint macros from Windows users that contain references to Designs, you cannot run them in PPT 2004, nor implement the equivalent in AppleScript. Up until now (Office 2004), you would have to omit them from your VBA macros and, for the time being, from your scripts too. Perhaps there is a way to work around the problem using slide master. But there is a chance that Designs, and brand new features in Office 2008 too, will soon become scriptable, unrelated to the VBA in older versions. The AppleScript model is now poised to move ahead on its own. So do look out for Designs, and other AppleScript classes and commands, in Office 2008.

Working with Document Properties

PowerPoint and the other Office applications maintain a set of document properties that contain useful information. To access any of these properties, you need to know the name of the property you're looking for. This macro will give you a list of them:

Sub ListBuiltInProperties()

Dim x As Long

On Error Resume Next

Debug.Print "BEGIN ===================================="

With ActivePresentation.BuiltInDocumentProperties

For x = 1 To .Count

Debug.Print "Property Number: " & CStr(x)

Debug.Print "Property Name: " & .Item(x).Name

Debug.Print "Property Value: " & .Item(x).Value

Next

Debug.Print "END ===================================="

End With

End Sub

Here's the AppleScript equivalent:

tell application "Microsoft PowerPoint"

     set theLog to "BEGIN =============================" & return



 


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.