LoginSignup
4
9

More than 5 years have passed since last update.

ExcelVBAでIE操作 Windows7→Windows10で起きたこと

Last updated at Posted at 2018-05-01

・VBAでInternetExplorerを自動で操作してました。
・Windows7からWindows10に移行しました。

すると、
IE.navigate "url" で、
特定のURLのみ、IEが空っぽになってしまう不具合が発生しました。

【対策まとめ】
・CreateObject("InternetExplorer.Application")ではなく、New InternetExplorerMediumを利用
・Sleepの宣言を書き換える

【詳細】
ググったところ、
「Excel VBAでIE操作時にオートメーションエラーが出た時は、対象のURLが「信頼済みサイト」に登録されているからかもしれない。」
https://qiita.com/3mc/items/da045e86d25ef697ec43

こちらで

CreateObject("InternetExplorer.Application")ではなく、New InternetExplorerMediumを利用します。

と書いてあったので、
そのとおりにしたら動きました。

=======================================

と思ったら、まだエラー
どうやら sleep がうまくいかないらしい。

#If VBA7 Then
Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal ms As LongPtr)
#Else
Private Declare Sub Sleep Lib "kernel32" (ByVal ms As Long)
#End If

こうすると良いらしい

4
9
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
4
9