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



     tell application "Microsoft Excel"

          tell thisBorder

              set line style to continuous

              set weight to border weight thick

              set color index to 3

          end tell

     end tell

end Customize

You will note that it is possible to send an application object out to an external handler as a parameter even though that takes it outside the Excel application block. The handler can still accept the item (which it will know as border id border edge left of cell "D10" of active sheet of application "Microsoft Excel") to pass back into the application tell block within the handler when called.

Conditional Formatting

Conditional formatting is applied using the format condition object in the Excel Suite. You will note that it is an element of range class, which may have none, or several of them. (It seems to be limited here to three per range.) Each conditional format may have at most three conditions, and the formats that can be set are for font, interior (background) and border. For instance, in VBA, this will apply a bold green font to values between 0 and 10:

With ActiveSheet.Range("B1").FormatConditions

   .Delete 'Delete existing conditional formats

   With .Add(Type:=xlCellValue, _

             Operator:=xlBetween, _

             Formula1:="0", _

             Formula2:="10").Font

      .Bold = True

      .Italic = False

      .ColorIndex = 4

   End With

End With

Here is the AppleScript version, which works delightfully once you get the syntax right. It is quite interesting to study:

tell application "Microsoft Excel"

     tell range "B1" of active sheet

          try

              delete (every format condition)

          end try

          set newFormatCondition to make new format condition at end ¬

              with properties {format condition type:cell value, condition operator:¬

                   operator between, formula1:"0", formula2:"10"}

          tell font object of newFormatCondition

              set {bold, italic, font color index} to {true, false, 4}

          end tell

     end tell

end tell

Format conditions are elements, not properties, of range, so you can delete any existing ones before making new ones, a good idea when you are making your first format condition for a range in a workbook that may have passed through other hands or has been around. (If you go on to make another format condition at the same range for different conditions, obviously omit the delete command if you want to keep the ones you've just made.) Put the delete command in a try block because it will error if there are no existing format conditions.



< 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