2016-01-27T22:40:16+09:00

Excel のチャートのサイズを数値入力で設定する AppleScript

Excel のシート上チャート(グラフ)のサイズをそろえたい事がままあります。手で微調するのは再現性が乏しいので、数値入力できる AppleScript を作りました。

on run
try
main()
on error msg number errno
if errno is not -128 then
activate
display alert msg message "Error Number : " & errno
end if
end try
end run

on main()
tell application id "com.microsoft.Excel"
tell chart area object of active chart
set h to height
set w to width
end tell
end tell

activate
if h is missing value then
display alert "No active chart."
return
end if
set defans to (w as text) & " x " & (h as text)
set a_result to display dialog "Enter new chart size (width x height) :" default answer defans
set new_size_text to text returned of a_result

if new_size_text is defans then
return
end if

set w to (word 1 of new_size_text) as number
set h to (word 3 of new_size_text) as number

tell application id "com.microsoft.Excel"
tell chart area object of active chart
set height to h
set width to w
end tell
end tell
end main

スクリプトメニューなどから起動すると良いでしょう。

Excel のシートで適当なチャートを選択して実行すると、次のようなダイアログが表示されます。ダイアログには、「幅 x 高さ」という書式で現在のサイズが表示されます。

この AppleScript は Excel 2008 と Mac OS X 10.8.5 で開発しました。

最新の環境でテストしていないのが玉に傷。