-
Mar 10th, 2008, 08:32 AM
#1
Thread Starter
New Member
IE Automation - vba
Hello VB Forums,
I have been trying to get some help regarding this topic from other forums they have proven to be very unhelpful.
I shouldnt think this will be too difficult for any experienced programmer so I hope I am able to find some help on this forum.
There are a couple of things I need to understand for automating IE using a Macro/VBScript.
I am a semi-beginner user of vba codes and I only got as far as the codes below as an exercise for IE automations.
Essentially, I would like to do the following:
1. click on a hyperlink on 1st IE window to open 2nd window
2. click on a couple of buttons on the second IE window, close 2nd IE window and move back to the 1st IE window.
(I understand this involves knowing the "handle" / Names of the windows and being able to switch from each other?)
I would be grateful if anyone can assist me on this, many thanks.
regards,
Ed
Please understand that the below is only an exercise
Code:
Sub Search_Google()
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate "http://www.google.com" 'load web page google.com
While IE.Busy
DoEvents 'wait until IE is done loading page.
Wend
IE.Document.all("q").Value = "what you want to put in text box"
ie.Document.all("btnG").Click
'clicks the button named "btng" which is google's "google search" button
While ie.Busy
DoEvents 'wait until IE is done loading page.
Wend
End Sub
-
Mar 10th, 2008, 10:49 AM
#2
Addicted Member
Re: IE Automation - vba
You can open a new window through the DOM by setting the link's target to a _blank or such.
Code:
IE.document.links(0).target = "_blank"
IE.document.links(0).Click
This isn't a great way since you will then (unless I am mistaken) need to use API to find the new window.
I would suggest possibly creating two IE objects.
Loading the first as you have. Then instead of clicking the link simply grab the Href and load it into the second IE object.
Code:
Dim IE As Object
Dim IE2 As Object
Sub Search_Google()
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "http://www.google.com" 'load web page google.com
While IE.Busy
DoEvents 'wait until IE is done loading page.
Wend
Dim LinkHref As String
LinkHref = IE.document.links(0).href
Set IE2 = CreateObject("InternetExplorer.Application")
IE2.Visible = True
IE2.Navigate LinkHref
While IE.Busy
DoEvents 'wait until IE is done loading page.
Wend
End Sub
Private Sub Command1_Click()
Search_Google
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set IE = Nothing
If TypeName(IE) <> "Nothing" Then Unload IE
Set IE2 = Nothing
If TypeName(IE2) <> "Nothing" Then Unload IE2
End Sub
Since you now have another IE object to reference the new window it is no different than simply doing a IE2.document.links(INDEX).click or whatever you want.
I don't doubt there is probably a better way,
Mike
-
Mar 10th, 2008, 11:18 AM
#3
Re: IE Automation - vba
Moved to Office Development
-
Mar 10th, 2008, 11:44 AM
#4
Thread Starter
New Member
Re: IE Automation - vba
Thanks for the prompt response MikeJoel, I will take a look and get back to you
Regards,
Ed
-
Mar 11th, 2008, 04:12 AM
#5
Thread Starter
New Member
Re: IE Automation - vba
Your codes are very help, thanks.
Though any chance you can give me an example for selecting javascripts on the google map webpage, the send button on the right above the map.
Many thanks
Regards,
Ed
http://maps.google.co.uk/maps?hl=en&tab=wl
-
Mar 11th, 2008, 04:42 PM
#6
Addicted Member
Re: IE Automation - vba
Originally Posted by papapa
Your codes are very help, thanks.
Though any chance you can give me an example for selecting javascripts on the google map webpage, the send button on the right above the map.
Many thanks
Regards,
Ed
http://maps.google.co.uk/maps?hl=en&tab=wl
I don't really understand what you mean by "selecting javascipts".
To click the search maps button use,
IE.Document.All("q_sub").Click
To click the button.
To find the Names and IDs of the elements just look at the page's source code.
Mike
-
Mar 12th, 2008, 03:42 AM
#7
Thread Starter
New Member
Re: IE Automation - vba
Many thanks MikeJoel, I will take a look and get back to you =)
Regards,
Ed
-
Jun 17th, 2009, 10:48 PM
#8
New Member
Re: IE Automation - vba
Hi
Is it possible to access contents of a page that comes after login page
means i have automated login to a site by putting usename and password
and clicked on submit
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate2 URL
Do Until IE.ReadyState = READYSTATE_COMPLETE
Loop
IE.Visible = True
IE.Document.all("userName").Value = Worksheets("Sheet1").userid.Text
IE.Document.all("passWord").Value = Worksheets("Sheet1").pwd.Text
IE.Document.all("Submit").Click
now i want a click on the link from the first page that comes after login
IE.Document.Links(0).target = "_blank"
IE.Document.Links(0).Click
but I can not use the same IE object to access link, text box or buttons from next page
at the begining of this thread some ' handle ' is mentioned how to use this concept ?
Please guide ...
Thanks in advance
-
Sep 10th, 2009, 06:39 AM
#9
New Member
Re: IE Automation - vba
Thats a wonderfull explanation.
I have a problem with mine, instead of it being a submit button, mine is a link with a javascript:
javascript: document.authform.submit();
How do I get this to work?
-
Sep 10th, 2009, 07:08 AM
#10
New Member
Re: IE Automation - vba
Sorry yea it works now didnt see the bit with the link, must be having a bad day today in retrospect lol, wonderfull!
How do I select Radio buttons and select or drop down boxes?
Thats really what I want out of this.
Then to be able to say does a certain text exist in web page, then logout and close internet explorer, is this possible?
Thats wonderfull so far, saved me a whole lot of programming this has.
-
Oct 20th, 2011, 03:05 PM
#11
New Member
Re: IE Automation - vba
Important:
Set IE2 = Nothing
is not enought for clean up!
Don't forget
EI2.Quit
Otherwise you run in trouble (memory, processes, the computer become extremely slow, ...)
I had to learn it the hard way, when extending ie automation in an excel-sheet we use for daily statistic and share it via the syncing.net software in our company. More than 30 pc got it, all pc became terrible slow, ...
Let's formulate it positive, colleagues were happy after the quit line was inserted and the count of iexplorer processes was not increasing anymore (every instance consuming 100 MB of memory).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|