IE6 Automation in VBA - automating child page on butt******* in parent page

Bhups

New Member
Joined
Jan 29, 2010
Messages
7
Hi,

My query is regarding internet explorer 6 automation via code in VBA (Excel 2003). I'm trying to open a page on clicking a button in main page.

I'm able to open both parent and child pages via VBA, but now want to automate events (like radio btn click etc) in child page.

Could you please help me in achieveing this?

below is my initial code -

Rich (BB code):
'========
Sub ListLinks()
Dim IeApp As InternetExplorer
Dim sURL As String
Dim IeDoc As Object
Dim i As Long
 
'Create new instance of IE
Set IeApp = New InternetExplorer
 
'Make it visible - some things don’t work
'unless it’s visible
IeApp.Visible = True
 
'define the page to open
sURL = "http://test/welcome.aspx"
 
'navigate to the page
IeApp.Navigate sURL
 
'Pause the macro using a loop until the
'page is fully loaded
Do
Loop Until IeApp.ReadyState = READYSTATE_COMPLETE
 
'store the Document object
Set IeDoc = IeApp.Document
 
 
'click a button on the main page
Set ElementCol = IeDoc.getElementsByTagName("INPUT")
For Each btnInput In ElementCol
If btnInput.Value = "Open" Then
Set IeApp.Document = btnInput.Click 'This will open up another IE window
Exit For
End If
Next btnInput
 
'Clean up
Set IeApp = Nothing
IeApp.Quit
 
End Sub
'===========
Thanks,
Bhups
 
Last edited by a moderator:

Some videos you may like

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
75,562
Office Version
365
Platform
Windows
What do you mean by 'parent' and 'child' pages?

I don't think I've ever heard that concept mentioned in reference to web pages.:)

By the way if you do want help with something like this you'll need to supply a bit more information.

Probably the most important thing is a valid URL, and it doesn't look like the one in your code is.:)
 

Bhups

New Member
Joined
Jan 29, 2010
Messages
7
Hi Norie,

By Parent I meant - the page loaded 1st in the above code i.e. 'http://test/welcome.aspx'

and child as the subsequent page that opens on clicking a button in parent page. I want to automate this page which opens up on button click.
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
75,562
Office Version
365
Platform
Windows
Like said more information is needed to help with this sort of thing - and that is not a valid URL.

I can't access it anyway.:
 

Bhups

New Member
Joined
Jan 29, 2010
Messages
7
here is the code with sample url. I want to automate the 2nd page that opens up -

Sub ListLinks()
Dim IeApp As InternetExplorer
Dim sURL As String
Dim IeDoc As Object
Dim i As Long

'Create new instance of IE
Set IeApp = New InternetExplorer

'Make it visible - some things don’t work
'unless it’s visible
IeApp.Visible = True

'define the page to open
sURL = "http://www.tfl.gov.uk/"

'navigate to the page
IeApp.Navigate sURL

'Pause the macro using a loop until the
'page is fully loaded
Do
Loop Until IeApp.ReadyState = READYSTATE_COMPLETE

'store the Document object
Set IeDoc = IeApp.Document


'click a button on the parent page
Set ElementCol = IeDoc.getElementsByTagName("INPUT")
For Each btnInput In ElementCol
If btnInput.Value = "Search" Then
btnInput.Click
Exit For
End If
Next btnInput

'Clean up
'Set IeApp = Nothing
'IeApp.Quit

End Sub
 

Tom Schreiner

Well-known Member
Joined
Mar 18, 2002
Messages
6,867
See the last two procedures in particular. Also note the use of module level variables.

Code:
Option Explicit

Private WithEvents IeApp As InternetExplorer
Private WithEvents NewWindow As InternetExplorer

Sub ListLinks()
Dim sURL As String
Dim IeDoc As Object
Dim i As Long
Dim ElementCol As Object
Dim btnInput As Object

'Create new instance of IE
Set IeApp = Nothing
Set IeApp = New InternetExplorer

'Make it visible - some things don’t work
'unless it’s visible
IeApp.Visible = True

'define the page to open
sURL = "http://www.tfl.gov.uk/"

'navigate to the page
IeApp.Navigate sURL

'Pause the macro using a loop until the
'page is fully loaded
Do
Loop Until IeApp.ReadyState = READYSTATE_COMPLETE

'store the Document object
Set IeDoc = IeApp.Document


'click a button on the parent page
Set ElementCol = IeDoc.getElementsByTagName("INPUT")
For Each btnInput In ElementCol
If btnInput.Value = "Search" Then
btnInput.Click
Exit For
End If
Next btnInput

'Clean up
'Set IeApp = Nothing
'IeApp.Quit

End Sub

Private Sub IeApp_NewWindow2(ppDisp As Object, Cancel As Boolean)
    Set NewWindow = New InternetExplorer
    Set ppDisp = NewWindow
End Sub


Private Sub NewWindow_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    'work with your new window reference here
    Debug.Print NewWindow.LocationURL
End Sub
 

Bhups

New Member
Joined
Jan 29, 2010
Messages
7
sorry Tom, I'm very new to VBA and trying to learn via this forum. Could you please modify my example to showcase the usage of your functions?
 

Bhups

New Member
Joined
Jan 29, 2010
Messages
7
Thanks alot Tom, I'm able to open the 2nd page now.

But still facing a problem with using the document object of 2nd ie window to click an event (say, a button called 'Search')

any idea on how this can be achieved?
 

Watch MrExcel Video

Forum statistics

Threads
1,099,622
Messages
5,469,762
Members
406,668
Latest member
ElizaR

This Week's Hot Topics

Top