結論
Applicationオブジェクトのプロパティを使ったエラーの場合、ActiveWindow等のウィンドウのオブジェクトのプロパティに対して処理する。
Application.Left = 5
Application.Top = 0
Application.Width = 727.714285714286
Application.Height = 910.857142857143
↓
With ActiveWindow
.Left = 20
.Top = 0
.Width = 727.714285714286
.Height = 910.857142857143
End With
経緯
macOSのExcelでウィンドウの制御をしていたところ、「オブジェクト'Left'のメソッド'_Application'が失敗しました。」というエラーが出て処理が進まなくて困っていた。
Application.Left = 5
Application.Top = 0
Application.Width = 727.714285714286
Application.Height = 910.857142857143
Windowsだと何もエラーが出なかったのに、macOSだと出るエラーで困った。
ふと、なんで自分はApplicationオブジェクトのLeftプロパティに代入しているのかなと思った。ウィンドウの制御なのに、ApplicationオブジェクトのLeftプロパティを使っている。
試しに普通のウィンドウ制御を調べてみると以下のような書き方をしていた。
With ActiveWindow
.WindowState = xlNormal
.Top = 1
.Left = 1
.Height = Application.UsableHeight
.Width = Application.UsableWidth
End With
こんな風に書くために以下のようにするとエラーが出なくなって処理が正常に動いた。
With ActiveWindow
.Left = 20
.Top = 0
.Width = 727.714285714286
.Height = 910.857142857143
End With
とりあえず閃いてよかった。