Mac OSの使い方/Mac OS 関連情報

Excel + AppleScript(3ページ目)

ここでは、Microsoft Excel を使ったAppleScriptの使い方を紹介します。

木下 幹司

執筆者:木下 幹司

Macガイド


その他、Excelのスクリプトでの記述ポイント


(tell application "Microsoft Excel" ~ end tell の部分は省略。なお、それぞれの詳細はスクリプトエディタの ファイル > 用語説明を開く… で Microsoft Excel を開いて調べてください)

●セルの指定
range "A1"
 -- properties of range "A1" とすると結果ウインドウに取得可能な属性が一覧されます

●セルを数字で指定する
range (cell 1 of colmun 2)
 -- B1のこと

●2つ以上のセルを結合
merge range "A1:B1"
 -- A1からB1を結合する

●「折り返し」を変更する
set wrap text of range "A1" to true
 -- true で折り返しする、false で折り返ししない

●セルの書式を「上揃え」にする
set vertical alignment of range "A1" to vertical alignment top
 -- vertical alignment top というのが vertical alignment の属性名です。vertical alignment bottom なら下揃えとなります。詳しくはスクリプトエディタの用語説明でExcelの用語説明を開いて、vertical alignment で検索してみましょう。

●フォントサイズの変更
 set font size of font object of range "A1" to 15
 -- A1 のフォントサイズを15ポイントに変更します

●フォントカラーの変更
 set color of font object of range "A1" to {255,255,255}
 -- 文字色を白に変更

●文字をボールドに変更
 set bold of font size of font object of range "A1" to true

●文字にアンダーラインを追加
set underline of font object of range "A1" to underline style single
 -- underline style single という形式のアンダーラインを追加

●コメントを追加
 add comment range "A1" comment text "コメントの内容"
 -- "コメントの内容"というコメントが付加されます。AppleScriptの一般的な書き方とは少し異なるので、注意

●色でセル背景を塗りつぶし
 set color of interior object of range "A1" to {255,0,0}
 -- セルの背景を変更します

●罫線の追加
罫線は、セルの上下左右に対して個別に設定する必要があります。なお、書き方も特殊なので注意しましょう。たとえば、セルA1の上下左右にいちばん細い罫線を追加する場合、以下のように書く必要があります。(border weight thin が太さの種類名)
tell application "Microsoft Excel"
   set theborder to get border range "A1" which border border top
   set weight of theborder to border weight thin

   set theborder to get border range "A1" which border border left
   set weight of theborder to border weight thin

   set theborder to get border range "A1" which border border right
   set weight of theborder to border weight thin

   set theborder to get border range "A1" which border border bottom
   set weight of theborder to border weight thin
end tell


【関連情報】
Mactopia Japan : Office 2004 for Mac
Mactopia Japan:Office 2004 を自動化!AppleScript 体験
Mactopia AppleScript Resources
Office 2004 限定プレミアムパック登場!(from All About)


【編集部おすすめの購入サイト】
楽天市場で MAC 関連の商品を見るAmazon で MAC 関連の商品を見る
  • 前のページへ
  • 1
  • 2
  • 3
※記事内容は執筆時点のものです。最新の内容をご確認ください。
※OSやアプリ、ソフトのバージョンによっては画面表示、操作方法が異なる可能性があります。

あわせて読みたい

あなたにオススメ

    表示について

    カテゴリー一覧

    All Aboutサービス・メディア

    All About公式SNS
    日々の生活や仕事を楽しむための情報を毎日お届けします。
    公式SNS一覧
    © All About, Inc. All rights reserved. 掲載の記事・写真・イラストなど、すべてのコンテンツの無断複写・転載・公衆送信等を禁じます