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



Font Format

Font formats are set using the cell‘s Font object. You can apply multiple properties at once:

   With ActiveSheet.Range("A1").Font

      .Name = "Verdana"

      .FontStyle = "Bold"

      .Size = 12

      .Strikethrough = False

      .Superscript = False

      .Subscript = False

      .OutlineFont = False

      .Shadow = False

      .Underline = xlUnderlineStyleDouble

      .ColorIndex = xlAutomatic

   End With

In AppleScript:

tell application "Microsoft Excel"

     tell font object of range "A1" of active sheet

          set {name, font style, font size, strikethrough, superscript, subscript, ¬

              outline font, shadow, underline, font color index} to {"Verdana", "Bold", ¬

              12, false, false, false, false, false, underline style double, color index automatic}

     end tell

end tell

This time I chose to set all properties at once in a list. It is easier, of course, to keep track of which property is set to which value if you do each on a separate line.

The color index property refers to the 56 colors available in the color palette. That's the same 56 colors as in the palette available in Format/Cells…/Font/Color, rather than the Formatting Palette and Toolbar's reduced palette of 40 colors. But the colors are in a completely different order – the "default palette" used by VBA and AppleScript must date back quite a few years. The correct palette layout, with identifying index numbers, is in the Excel AppleScript Reference under Text Suite/Classes/Font.

In addition to the eight custom colors that you can set using the number format property, you can use the font color index property to set the font color:

      ActiveSheet.Range("A1").Font.ColorIndex = 3   'Default palette red

In AppleScript:

     set font color index of font object of range "A1" of active sheet to 3

Take a good look at the color index enumeration for the font color index property of font class (Text Suite). It gives three so-called constants as available: color index automatic (that's generally black), color index none, and something called 'a color index integer' which will compile and run without error, but turns any existing color black, so it must be defaulting to automatic.

This is "covering" for what ought really to be another 56 constants – namely the numbers 1 through 56. In VBA, if you check the Object Browser you'll see only xlAutomatic and xlNone listed, which have (as all xl and vb constants do) their own numeric version (large negative numbers). But numbers 1-56 have also been reserved. Only the VBA Help tells you that. In AppleScript, some sort of reference to the numbers needed to be given but that "a color index integer" entry is just a dummy, or bogus, constant. It's a description masquerading as a constant. I suggest a reason for this at the end of this Excel chapter. An actual short description, if not "1-56" ought to be listed instead. But the Excel AppleScript Reference, to its credit, does give a full explanation.

You can set a "Microsoft" RGB value for the color, but Excel will choose the “closest” color available in the palette. It's really quite inadequate, but at least gets pure red, green and blue all right:

      ActiveSheet.Range("A1").Font.Color = RGB(255, 0, 0)

becomes:

     set color of font object of range "A1" of active sheet to {255, 0, 0}

See the PowerPoint chapter for a full discussion of Microsoft's RGB vs. AppleScript RGB.

The Color Palette



< 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