vbscript - Bring Internet Explorer Application window to front

浪尽此生 提交于 2019-12-25 09:10:14

问题


I have a script where I create an IE window through CreateObject("InternetExplorer.Application"). The problem is, whenever I run this script, it always opens behind whatever else might already be open on my machine. I want this IE window to open on TOP of everything else. It does not have to be "always on top", like the option in Task Manager, but it should at least initially open on top. After that, I don't care what happens. I have searched high and low and have been unable to find a way to achieve this. I have tried appactivate and focus() but neither of those seem to work. Any suggestions?

I am running Windows 7 with IE 11


回答1:


You probably have the problem because the title of the IE window is not exactly the title of the page (ie. "Yahoo - Internet Explorer") Therefore you must bring it to the front before you start navigating to the page :

Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
CreateObject("WScript.Shell").AppActivate "Internet Explorer"
ie.Navigate "http://www.yahoo.com/"



回答2:


I found the sequence affects the behavior. Don't make IE visible until after it has finished loading.

Set ie = CreateObject("InternetExplorer.Application")
ie.Navigate "http://www.google.com"
While ie.Busy Or ie.ReadyState <> READYSTATE_COMPLETE
    DoEvents
Wend
ie.visible = True 
DoEvents



回答3:


I messed around with a bunch of the solutions on the internet but eventually found the easiest one that worked.

Set objExplorer = CreateObject ("InternetExplorer.Application")
objExplorer.document.focus()


来源:https://stackoverflow.com/questions/41127146/vbscript-bring-internet-explorer-application-window-to-front

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!