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



< 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