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



Dim oSh As Shape

Dim colSch As ColorScheme

 

' Get a reference to the current active presentation

Set oPres = ActivePresentation

 

' Do something with each slide in the presentation

For Each oSl In oPres.Slides

' Set the background color scheme of each slide to a pale aquamarine

Set colSch = oSl.ColorScheme

colSch.Colors(ppBackground).RGB = RGB(222, 246, 241)

' and do something with each shape on each slide

For Each oSh In oSl.Shapes

' move it 36 points (.5 inch) to the right

oSh.Left = oSh.Left + 36

Next

Next

Here's the AppleScript version of the same thing:

tell application "Microsoft PowerPoint"

     set oPres to active presentation

     repeat with oSl in (get every slide of oPres)

          set color for (color scheme of oSl) at background scheme ¬

              to color {222, 246, 241}

          repeat with oSh in (get every shape of oSl)

              tell oSh

                   set left position to (get left position) + 36

              end tell

          end repeat

     end repeat

end tell

We skip the Dim declarations of course, and move on to business, using the same variables as the VBA version for clarity, although there is no need in AppleScript to use initial characters of variables, such as "o" , "s" and "l" to remind yourself to use the correct types for Object, String and Long, for example, since it makes no difference in AppleScript. Personally, I like to use variable names that increase the "Englishness" of the statements, such as "thePresentation", "theSlide" and "theShape", unless I'm getting bored with typing long names and might just use "p", "sl" and "sh". It's entirely up to personal taste. Although, when writing scripts to be read by others (or by yourself, some months or years later) using explanatory terms such as "theSlide" and "theShape" helps make the script self-commenting without needing a lot of extra comments, and much easier to follow than the perl-like obscurity of "p" and "s".

Anyhow, this particular macro translates quite easily to AppleScript. colorScheme is a highly unusual class that has no properties whatsoever (such as, e.g., 'background scheme color', 'fill scheme color', etc.) for us to get and set in the normal way – which would be far preferable. Instead (no doubt to do with inheriting the structure from VBA, where ColorScheme.Colors is a Method rather than a Property, with enumerated pp constants as arguments), you have to use the proprietary get color for and set color for commands whose at parameter accesses an identical enumeration of constants: here we use the background scheme constant.

The values for the color need some comment. In VBA, the RGBColor Object is a Long made from an RGB Property of an array of three 0-255 based integers, being an 8-bit Red-Green-Blue composite. In Office AppleScript (meaning Word, Excel, and PowerPoint only here), any property or class whose type is denoted as color wants the same three 0-255 based integers as a list, in list braces: {222, 246, 241}. This is a sort of "Microsoft color" class that ought to be defined as such in the application dictionaries. It is very convenient here when converting VBA macros to AppleScript, because you use the same three numbers for the R, G, B. However, the true Apple-defined RGB color class in AppleScript is a 16-bit RGB list of three 0-65535 integers. If you ever want to transfer a color from Word, Excel or PowerPoint to another Mac application, including Entourage (whose categories have a color property) you would get a completely different color if you used the same three numbers. The way to do it is to square each integer, as in this handy subroutine:

ApplifyMSColor({222, 246, 241})



< 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