We help IT Professionals succeed at work.

How do I activate (bring to front) an internet explorer window in VBScript?

Medium Priority
18,215 Views
Last Modified: 2012-05-06
Hi, I have a VBscript that opens up 3 windows in IE, and it resizes them so they tile in a certain arrangement on my screen. I want to know how I can activate (or bring to the front) one of the windows so I can send text to it. Attached is my code. Thanks!
 
 
 
On Error Resume Next
 
Set objShell = CreateObject("Shell.Application")
Set objShellWindows = objShell.Windows
Set IE1 = objShellWindows.Item
Set IE2 = objShellWindows.Item
Set IE3 = objShellWindows.Item
 
URL1 = "http://zip4.usps.com/zip4/welcome.jsp"
URL2 = "http://maps.google.com/"
URL3 = "http://fedexifc.infousa.com/QAA/demo/Login.aspx"
 
IE3.Navigate2 URL3
If err.number <> 0 Then
 Set IE3 = wscript.CreateObject("internetexplorer.application")
 
 InfoUSALogin(IE3)
 
End If
 
IE1.Navigate2 URL1
If err.number <> 0 Then
 Do While IE3.Busy
 Loop
 Set IE1 = wscript.CreateObject("internetexplorer.application")
 IE1.Visible = True
 IE1.Navigate2 URL1
 IE1.Height = 525
 IE1.Width = 642
 IE1.Left = 0
 IE1.Top = 0
End If
 
 
 
IE2.Navigate2 URL2
If err.number <> 0 Then
 Set IE2 = wscript.CreateObject("internetexplorer.application")
 IE2.Visible = True
 IE2.Navigate2 URL2
 IE2.Height = 1050
 IE2.Width = 642
 IE2.Left = 642
 IE2.Top = 0
End If
 
 
Set IE1 = Nothing
Set IE2 = Nothing
Set IE3 = Nothing
Set objShellWindows = Nothing
Set objShell = Nothing
 
 
 
Private Sub InfoUSALogin(ie)
Dim wshShell
 
Set wshShell = WScript.CreateObject("WScript.Shell")
 
ie.Visible = True
ie.Navigate2("http://fedexifc.infousa.com/QAA/demo/Login.aspx")
 
Do while ie.Busy
Loop
 
wshShell.SendKeys "username"
wshShell.SendKeys "{TAB}"
wshShell.SendKeys "password"
wshShell.SendKeys "{TAB}"
wshShell.SendKeys "group"
wshShell.SendKeys "{TAB}"
wshShell.SendKeys "{ENTER}"
 
ie.Height = 525
ie.Width = 642
ie.Left = 0
ie.Top = 500
 
End Sub

Open in new window

Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2007
Commented:
Try using the wscript.shell method of AppActivate...

Example:

Set objWShell = CreateObject("Wscript.Shell") 
Set objShell = CreateObject("Shell.Application")
Set objShellWindows = objShell.Windows
Set IE1 = objShellWindows.Item
URL = "http://maps.google.com/"
IE1.Navigate2 URL
wscript.sleep 5000
objWShell.appactivate ("Google Maps") 'Title of the window...

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Michel PlungjanIT Expert
CERTIFIED EXPERT
Top Expert 2009

Commented:
does

ie.Focus

or

ie.Focus()
work?

Author

Commented:
Thank you for the solution!
CERTIFIED EXPERT
Top Expert 2007

Commented:
Happy to help - thanx for the grade! :^)
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.