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



     end repeat

end tell

AppleScript's text operators – all except AppleScript's text item delimiters (more on them later) – are case insensitive unless you've placed them inside a considering case block. So we do not need to go through any contortions as in the VBA code to compare any word with "(Hide)" or "(hide)". And although standard AppleScript without scripting additions does not have wildcards or regular expressions, it does have contains, which does the job perfectly.

Now here's a case where every worksheet whose… does not work, because Excel can't deal with a property (e.g., visible) of such a construction, as mentioned at the end of Chapter 3.

set visible of (every worksheet in active workbook ¬

          whose its name contains "(Hide)") to false

--> ERROR: Can't set visible of every worksheet of active workbook whose name contains "(Hide)" to false.

So here you need to use a repeat loop.

But there's a subtle twist you need to be aware of: the VBA code above used Not – i.e., ws.Visible = False – as a synonym for the enumeration xlHidden. To prevent the worksheet from appearing even in the Format/Sheet/Unhide dialog, it would instead set the Visible property to xlVeryHidden:

   ActiveSheet.Visible = xlVeryHidden

In AppleScript, that's:

set visible of active sheet to sheet very hidden

The correct enumeration for the visible property is, in AppleScript: sheet hidden, sheet very hidden and sheet visible, equivalent to VBA's xlHidden, xlVeryHidden and xlVisible. You can use true and false as synonyms for sheet visible and sheet hidden respectively if you wish, just as in VBA.

This is a bit clearer in the Object Browser of VB Editor if you check the actual Longs (numbers) of the enumerated constants. But it works in AppleScript too.

This is very convenient in making these VBA-to-AppleScript conversions, as I mentioned back in the open text file section: if the VBA macro writer used numbers instead of the enumerated xl or vb constants, you can generally just transcribe the same numbers into your AppleScript code even though it's not explicitly defined in the AppleScript dictionary which enumerated constants they refer to, nor even that these "number equivalents" exist for the constants.

Working with Columns and Rows

Alert: There are some very serious AppleScript bugs in Excel 2004 to do with columns and rows. Something was implemented incorrectly when the Columns and Rows Collection Objects were adapted for AppleScript. Thus:

     row 5 of (get used range of active sheet)

     column 7 of range "A1:P26" of active sheet

     range "G1:G26" of range "A1:P26" of active sheet

all produce something that is useful and functional, namely a range. The result is never referred to as a column or row, always as a range. But      

     column "G1:G26" of range "A1:P26" of active sheet

(i.e., referring to it as a column, rather than as a range) produces nothing – no result. So you can refer to columns and rows by index (number), never by address. Perhaps this will not be unexpected coming from VBA, where you would typically refer to Columns(7) and Rows(5). It doesn't jibe with what you would expect from the dictionary, where column, row and cell are all subclasses of range and inherit all its properties. That means you ought to be able to do the same with column, row and cell as you do for range, but you can't. For most purposes, if you stick to referring to columns and rows by index, and use range when using an address, things will be smoother.

Worse, and stranger, is that you cannot get anything useful for:

     rows of (get used range of active sheet)

     columns of range "A1:P26" of active sheet



< 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