VBS script to bring program to front

16,447

Solution 1

Try this:

Set ie = CreateObject("InternetExplorer.Application")
ie.Navigate "http://www.yahoo.com/"
Do While ie.Busy : WScript.Sleep 100 : Loop
ie.Visible = True
CreateObject("WScript.Shell").AppActivate ie.document.title

Solution 2

I have found that setting the Visible property to True after calling the AppActivate method works @daniel-cook.

Therefore, simply swapping the last 2 lines in @ansgar-wiechers' example produces the desired result.

Set ie = CreateObject("InternetExplorer.Application")
ie.Navigate "http://www.yahoo.com/"
Do While ie.Busy : WScript.Sleep 100 : Loop
CreateObject("WScript.Shell").AppActivate ie.document.title
ie.Visible = True
Share:
16,447
Trung Tran
Author by

Trung Tran

Updated on June 04, 2022

Comments

  • Trung Tran
    Trung Tran almost 2 years

    I am writing VBS code to open Internet Explorer and go to www.google.com However when I run the program, it opens and navigates to www.yahoo.com but the internet explorer is NOT the front window. Can anyone help me with this? Is there a code I can use to bring internet explorer to the front? Thank you all! Here is my code:

    Option Explicit
     Dim ie
    
    
    Set ie = CreateObject("InternetExplorer.Application")
    
    ie.Navigate("wwww.yahoo.com")
    

    One last question - Is there a code I can use to click a certain button that - specifically one that I can't get to by pressing "tab"?

    Thank you all!