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:

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
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.:)
 
Upvote 0
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.
 
Upvote 0
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.:
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0
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?
 
Upvote 0
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?
 
Upvote 0

Forum statistics

Threads
1,213,582
Messages
6,114,470
Members
448,574
Latest member
bestresearch

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top