By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,776 Members | 1,351 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,776 IT Pros & Developers. It's quick & easy.

Automate IE via VB - Change focus of object.

P: 7
Hi, im using VB to automate IE and its only my 3rd time. The website im trying to automate populates another IE window and I cant figure out how to change the focus of the automation to the new window? Any ideas?
Jan 24 '08 #1
Share this Question
Share on Google+
9 Replies


debasisdas
Expert 5K+
P: 8,127
can you please pass few more details what exactly you are trying to do .
Jan 25 '08 #2

P: 7
can you please pass few more details what exactly you are trying to do .
im using the code below to advance to a certain webpage. and once i get to that webpage i select an option. When i select that option a new window appears. I need to work with that new window, but be able to go toggle back to the other window when neccessary. When i try my code it never performs the actions i am asking on the new object. My code is right if i could just get it to recognize the new window and work on it.

[PHP
Set ie = CreateObject("InternetExplorer.application")
ie.Visible = True
ie.navigate ("Secure Info")
Set doc = ie.document
Set ctl = doc.getElementById("property(txtFormattedPolicy)")

ctl.Value = ""
ie.document.all.Item("btnRunSearch").Click **New window pops up here.

[/PHP]
Jan 25 '08 #3

P: 58
What is the URL to the popup window? Navigate to the URL using the browser object.
Jan 25 '08 #4

P: 7
The url changes constantly. It depends on what option i click. Is there another way besides navigating the original object to the new windows url?
Jan 25 '08 #5

P: 58
What if you create a new object that navigates to the popup URL? What exactly are you trying to automate?
Jan 25 '08 #6

P: 7
Im trying to automate my companies internet based system. The new url depends on alot of different information. Policy, username, client name.. etc...
Jan 25 '08 #7

P: 58
Check out Ken's last post at the following link.

http://www.vbaexpress.com/forum/printthread.php?t=1058

Expand|Select|Wrap|Line Numbers
  1. ' Tools -> References -> Microsoft Internet Controls
  2.  
  3. Sub Test()
  4.    ' Dim IE As Object
  5.    Dim sws As SHDocVw.ShellWindows
  6.    Dim i As Integer
  7.  
  8.    Set sws = New SHDocVw.ShellWindows
  9.  
  10.    For i = 0 To sws.count - 1
  11.       Debug.Print (sws.item(i).LocationURL)
  12.       ' Find the URL you want and set the IE object
  13.       ' Set IE = sws.Item(i).Document
  14.    Next i
  15. End Sub
Jan 25 '08 #8

P: 58
Open up a few IE windows, make sure one of the URL's is set to http://www.google.com and run the code.

Expand|Select|Wrap|Line Numbers
  1. ' Tools -> References -> Microsoft Internet Controls
  2.  
  3. Sub Test()
  4.    Dim IE As Object
  5.    Dim sws As SHDocVw.ShellWindows
  6.    Dim i As Integer
  7.  
  8.    Set sws = New SHDocVw.ShellWindows
  9.  
  10.    For i = 0 To sws.count - 1
  11.       If sws.item(i).LocationURL = "http://www.google.com/" Then
  12.          Set IE = sws.item(i).Document
  13.          Exit For
  14.       End If
  15.    Next i
  16.  
  17.    IE.All("q").Value = "Diablo II"
  18.    IE.All("btnG").Click
  19.  
  20.    Call Wait(IE)
  21. End Sub
  22.  
  23. Private Sub Wait(IE As Object)
  24.    While IE.ReadyState <> "complete"
  25.       DoEvents
  26.    Wend
  27. End Sub
Jan 25 '08 #9

P: 7
thank you. i believe i can make this work. how do i select a hyperlink once im on the page?

javascript:CSWCVC_linkChangePolicy
Feb 6 '08 #10

Post your reply

Sign in to post your reply or Sign up for a free account.