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:
Here is a sample search. You could do this with much less code but I wrote it as such for illustration.

Code:
Option Explicit

Private WithEvents IeApp As InternetExplorer
Private WithEvents NewWindow As InternetExplorer

'requires two references
'Microsoft Internet Controls
'Microsoft HTML Object Library
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)
    'using ontime allows the event to return
    Application.OnTime Now, Me.CodeName & ".ProcessNewWindow"
End Sub

Sub ProcessNewWindow()
    Dim Doc As HTMLDocument
    Dim Form As HTMLFormElement
    Dim KeyWords As HTMLInputTextElement
    Dim CompanyName As HTMLInputTextElement
    Dim Location As HTMLInputTextElement

    Set Doc = NewWindow.Document
    Set Form = Doc.getElementById("searchBoxForm_bottom")
    Set KeyWords = Doc.getElementById("keywordsInput_bottom")
    Set CompanyName = Doc.getElementById("companyName_bottom")
    Set Location = Doc.getElementById("location_bottom")
    
    KeyWords.Value = "Dry cleaning & laundry"
    CompanyName.Value = "Morrisons"
    Location.Value = "Camden Town"
    Form.submit
End Sub
 
Upvote 0

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

Forum statistics

Threads
1,215,819
Messages
6,127,047
Members
449,356
Latest member
tstapleton67

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