Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBS script to bring program to front

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!

like image 509
Trung Tran Avatar asked Sep 18 '26 05:09

Trung Tran


2 Answers

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
like image 180
Ansgar Wiechers Avatar answered Sep 21 '26 20:09

Ansgar Wiechers


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
like image 29
Paul M Edwards Avatar answered Sep 21 '26 21:09

Paul M Edwards



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!