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



Insert a Slide

Unfortunately, and unaccountably, there is no AppleScript equivalent of the InsertFromFile method that allows you to insert an existing file of saved slide(s) into a presentation. It's a bug, and should hopefully be made good in Office 2008 – look for an insert from file command.) In the meantime, here's a chance to try out do Visual Basic. You can still convert your macro, and when you get to a line using InsertFromFile, like this:

   ActivePresentation.Slides.InsertFromFile _

      "Macintosh HD:Users:Shared:Sales.ppt", 2, 3, 6

you would, for the moment, in PowerPoint 2004, use:

do Visual Basic "ActivePresentation.Slides.InsertFromFile _

     \"Macintosh HD:Users:Shared:Sales.ppt\", 2, 3, 6"

Note the escape backslashes \ before the internal quotes, and the fact that you do not need to close the outer AppleScript quotes for each line of the quoted VBA. And do remember that this line will fail in Office 2008 – you will need to replace it with (hopefully) the new AppleScript command at that time.

Working with Existing Slides and Shapes

Getting a selected slide or shape

Often you might run into VBA code like this:

Dim oSh as Object

Set oSh = ActivePresentation.Slides(4).Shapes(8)

With oSh

   .SomeProperty = "this"

   .AnotherProperty = "that"

End With

This is just a reminder from Chapter 2 that 1) in AppleScript you don't need to (and can't) declare (Dim) anything as typed; 2) there are no collection objects in AppleScript, so instead of ActivePresentation.Slides(4).Shapes(8), you refer to shape 8 of slide 4 of active presentation; and 3) you can use a tell block exactly as VBA uses a With block:

tell application "Microsoft PowerPoint"

     set theShape to shape 8 of slide 4 of active presentation

     tell theShape

          set some property to "this"

          set another property to "that"

     end tell

end tell

Furthermore, if you're setting 18 or so properties of theShape, you don't even need to set each one separately on its own line (although you can if you want to: it's sometimes easier to keep track of them that way): you can set them all in one long line using lists, like this:

tell theShape

      set {some property, another property} to {"this", "that"}

end tell

You must use the tell block if you want to set a list of properties in one line: you cannot do so using the alternative of syntax.

As mentioned just above, there is no name property of slide in AppleScript. But because it is so useful in VBA as a way of keeping track of and referring to slides you will very often find in the macros you want to convert that the author has named each slide and shape of interest for later reference. Many macros will start out by presuming that you have selected a slide or a shape, and then will proceed to name it for future reference:

With ActiveWindow.Selection.SlideRange

   .Name = "MyName"

End With

 

With ActiveWindow.Selection.ShapeRange

   .Name = "MyName"

End With

The VBA author will no doubt have been careful to specify that you must select only one slide or shape for the Name property, whether using the SlideRange or ShapeRange property as above, or by .Selection.Slides(n).) Unfortunately, you're going to have to dispense with all this since, as mentioned above, there is no selection object in AppleScript at present in PowerPoint 2004. You will have to wait for Office 2008 in the hope that it has a selection property of the application (and of presentation) to be able to do a direct "translation" of .Selection. Read on for a workaround for PowerPoint 2004 and comments about 2008.



< 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