1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

「オブジェクト'Left'のメソッド'_Application'が失敗しました。」の解決方法

Last updated at Posted at 2022-07-19

結論

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

スクリーンショット 2022-07-20 1.30.37.png

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

とりあえず閃いてよかった。

参考

Application.Width プロパティ (Excel) | Microsoft Docs

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?