スクスニップ

AppleScriptの断片をここに書く

Excel のウインドウ枠の固定を AppleScript で設定する

随分と更新が止まっていました。みこまやです。 まあ、誰も見てないのでいいか(笑)

業務でExcel のウインドウ枠の固定を手作業で行っていたのですが、シートが多数の場合、設定ミスが目立つようになってきました。 サンプルをググってみたら、日本語で書かれた記事が見当たらず、辿り着いたのは英語のページ。

ちょこっと自分なりにアレンジしたのが以下のスクリプト

set rowIndex to 5 --この行までが固定されます

tell application "Microsoft Excel"
    tell window 1
        try
            set freeze panes to false -- 枠固定を外す
        end try
    end tell
    tell active sheet
        select range ("A" & (rowIndex + 1 as string)) -- セルを選択
    end tell
    tell window 1
        set freeze panes to true -- 枠固定を実行
    end tell
end tell

tell 先が window と sheet に分かれるのがキモですかね。