vbscript - Bring Internet Explorer Application window to front
Solution 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/"
Solution 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
margentieri
Updated on June 04, 2022Comments
-
margentieri almost 2 years
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 triedappactivate
andfocus()
but neither of those seem to work. Any suggestions?I am running Windows 7 with IE 11
-
margentieri over 7 yearsFunny, I thought I tried pretty much exactly this, but it didn't work before. I don't think I had used CreateObject("WScript.Shell") with appactivate, so that might have been it. It was either that or @Noodles comment on the time constraint on setting a foreground window. I had a sleep in there that might have been messing things up. Thanks!
-
Admin over 7 yearsIE doesn't need to be the foreground window to be controlled by script. It will work happily invisible.
-
margentieri over 7 years@Noodles, yes, I am aware of that, but the whole point of the IE window for my application is to create a user interface to gather variable input to pass on to another application. I did not want the user of my script to have to try and find the IE window that my GUI is created in, I wanted that GUI to be immediately presented to them upon execution of my script. Thanks again for the insight regarding the time constrains on setting foreground windows!
-
Dave over 6 yearsThis results in an error: Compile Error: Syntax Error
-
Shooter McGavin over 6 yearsNot for me Dave. Which compiler are you using? I'm using WScript.
-
TBoulz over 4 yearsI know this is old, but this was a quick and easy way to avoid the issue.