methods of object "Internet Explorer"

T

Thirusivamani

I want to refer all the Methods (like Document, Forms) of the Object
"Internet Explorer". Where could i get these documents online? Please help me
out.
 
T

Thirusivamani

Hi JP. Thanks for the links. But i want to control the change event of a
select button in a page.

On changing a select button's value a function "ORFchange" is triggered in IE.

How do i automate this in VBA code?
 
J

JP

Sorry, I'm not familiar with events in the IE object model. As far as
I know, you click buttons on webpages, you don't monitor events the
way you do with a Userform in VBA. Website buttons don't really have
values, they have names which you would use to locate and click them.

Sorry I can't be more help here.

--JP
 
J

Joel

JP: I have a similar problem to an earlier posting. Can you help? thanks in
advance. The code below is for excel. I klnow excel very well but not all
the web apllications.

I buying a new car and the lcoal dealer wants to charge me to shipped a car
from another dealer. I'm trying to find the dealer who has the car. So I
want to get a list of all the car dealers in my area and then search each
inventory on the web.

I simply go to the Nissan wepage setting the zipcode. The page only returns
4 results. I then change the distance box in code to 50 miles and press the
Search button in code which returns 55 results. I'm have to manually break
the code because I can't get the code to wait for the Search to complete. I
also can get the 1st 10 reults, but the other results are on other pages and
can't find the data. Right now I'm trying to change the Sheet box from sheet
1 to sheet 2.

The webpage is writen in Java and I don't know Java, but do know Excel Macro
very well. Not sure if this is best way of getting data but have some code
that works. Having two problems as documented in the code

1) I can't get the code to wait for a Java script to complete. The code
does work when a webpage is loading.

2) I can only get the 1st 10 returned item out of 55 items. The rest of the
items are on additional pages and can't change sheets.



Sub GetDealers()
URL = "http://www.nissanusa.com/apps/dealerlocator"
Request = "?zipCode=07508&tool=Home.Locator"

Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True

'get web page
IE.Navigate2 URL & Request
Do While IE.readystate <> 4
DoEvents
Loop

'get search button
Set but = IE.document.getElementById("mainSearchButton")
'put distance in listbox on webpage
Set radius = IE.document.getElementById("radius")
radius.Value = "50"


'search again a larger distance
'Select Search button and activate
but.Select
but.Click
Set SearchResults = IE.document.getElementById("searchResults")
Do While IE.busy = True
DoEvents
Loop
'-------------------------------------------------------
' Cant get code to wait here for data to be retrieved.
'-------------------------------------------------------


Set SearchResultsCount = IE.document.getElementById("searchResultsCount")

With Sheets("Sheet1")
RowCount = 1
For Each Chld In SearchResults.Children
If Chld.innertext = "" Then
Exit For
End If
.Range("A" & RowCount) = Chld.innertext
RowCount = RowCount + 1
Next Chld
End With

'-------------------------------------------------------
' Can't get all pages of data. Only gets 1st 10 items.
'-------------------------------------------------------



'-------------------------------------------------------
' Other tags not used
'-------------------------------------------------------

Set pageTags = IE.document.getElementById("pageTags")
Set pagebg = IE.document.getElementById("pagebg")
Set cdpageContent = IE.document.getElementById("cdpageContent")
Set but2 = IE.document.getElementById("SearchButton")
Set allTabs = IE.document.getelementsbytagname("TABLE")
Set but2 = IE.document.getElementById("SearchButton")
Set crmEngine = IE.document.getElementById("crmEngine")
Set gBody = IE.document.getElementById("gBody")
Set movFlashGlobalNav = IE.document.getElementById("movFlashGlobalNav")
Set frameBgTop = IE.document.getElementById("frameBgTop")
Set frameBgBottom = IE.document.getElementById("frameBgBottom")
Set frameContent = IE.document.getElementById("frameContent")
Set SearchInput = IE.document.getElementById("SearchInput")
Set Topbar = IE.document.getElementById("Topbar")
Set dealerL = IE.document.getElementById("DealerL")
Set InputBox1 = IE.document.getElementById("Inputbox")
Set tmap1 = IE.document.getElementById("tmpa1")
Set pages = IE.document.getElementById("dealerLocator.searchResults.page")
Set movFlashBottomNav = IE.document.getElementById("movFlashBottomNav")

End Sub
 
J

JP

Joel,

Is this the whole code? I need to see how you are declaring the
objects you are using.


Thx,
JP
 
J

Joel

I solved the problem myself. I found Excel makes an excellent debug package
when debugging HTML code. You can easily write data to the spreadsheet from
a webpage like this

rowCount = 1
for each itm in IE.document.all
Range("A" & RowCount) = itm.innertext
nextt itm

It took a lot of work but below its my entire code. You need to have two
sheets in your workbook call "Dealers" , and "Cars" (remove double quotes).
First run Sub GetDealers. This will get all the dealers in a 100 mile radius
of zip code 07508. Then Run Sub GetCars.



Sub GetDealers()
'Dim PageNumber As Object
CR = Chr(13)
LF = Chr(10)

Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True

URL = "http://www.nissanusa.com/apps/dealerlocator"
Request = "?zipCode=07508&tool=Home.Locator"

'get web page
IE.Navigate2 URL & Request
Do While IE.readyState <> 4
DoEvents
Loop

'get search button
Set but = IE.document.getElementById("mainSearchButton")
'put distance in listbox on webpage
Set radius = IE.document.getElementById("radius")
radius.Value = "100"


'search again a larger distance
'Select Search button and activate
but.Select
but.Click
Set SearchResults = IE.document.getElementById("searchResults")

On Error Resume Next ' Defer error handling.
Do
Err.Clear
Set PageNumber = IE.document.getElementById("pageNumber")
Pages = PageNumber.Value
DoEvents
Loop While Err.Number <> 0
On Error GoTo 0


With Sheets("Dealers")
RowCount = 1

For PageCount = 1 To PageNumber.Length
PageNumber.Value = Format(PageCount, "@")
PageNumber.onchange

For Each Chld In SearchResults.Children
ChildRowCount = 1
For Each all In Chld.all
Sheets("Sheet3").Range("A" & ChildRowCount) = all.innertext
Sheets("Sheet3").Range("B" & ChildRowCount) = all.outerhtml
ChildRowCount = ChildRowCount + 1
Next all
If Chld.innertext = "" Then
Exit For
End If
Set DealerNumberObj = _
Chld.getelementsbytagname("A")
DealerNumberStr = DealerNumberObj.Item(1).pathname
dealerNumber = _
Val(Mid(DealerNumberStr, InStr(DealerNumberStr, "'") + 1))
.Cells(RowCount, "A") = dealerNumber

ColCount = 2
dealer = Chld.innertext
Do While InStr(dealer, CR) > 0
Data = Trim(Left(dealer, InStr(dealer, CR) - 1))

'remove leading CR and LF
Do While Left(Data, 1) = LF Or _
Left(Data, 1) = CR

Data = Mid(Data, 2)
Loop
dealer = Trim(Mid(dealer, InStr(dealer, CR) + 1))
If InStr(Data, "(") > 0 And _
ColCount = 4 Then

Distance = Trim(Mid(Data, InStr(Data, "(") + 1))
Distance = Trim(Left(Distance, InStr(Distance, ")") - 1))
CityState = Trim(Left(Data, InStr(Data, "(") - 1))
.Cells(RowCount, ColCount) = CityState
.Cells(RowCount, (ColCount + 1)) = Distance
ColCount = ColCount + 2
Else
.Cells(RowCount, ColCount) = Data
ColCount = ColCount + 1
End If
Loop

'remove leading CR and LF
Do While Left(dealer, 1) = LF Or _
Left(dealer, 1) = CR

dealer = Mid(dealer, 2)
Loop
.Cells(RowCount, ColCount) = dealer
RowCount = RowCount + 1
Next Chld
Next PageCount
End With
End Sub

Sub GetCars()

Dim DealerName As String
Dim City As String
Dim Distance As String
Dim Bodytype(2) As String
Dim BodyStyle As String

Bodytype(0) = "alt" 'sedan
Bodytype(1) = "alc" 'coupe

Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True

URL = "http://www.config.nissanusa.com/redirect.jsp"

Sheets("Cars").Cells.ClearContents
With Sheets("Dealers")
RowCount = 25
Do While .Range("A" & RowCount) <> ""
dealerNumber = .Range("A" & RowCount)
DealerName = .Range("B" & RowCount)
City = .Range("D" & RowCount)
Distance = .Range("E" & RowCount)

Request = "?make=nissan&" & _
"model=null&" & _
"year=null&" & _
"flow=browse&" & _
"dealer=" & dealerNumber & "&" & _
"next=Locate.SearchInventory&" & _
"nextInInventory=dealer_inventory&" & _
"rpl=false&x=&zip=07508&Site=&lang=en"

IE.Navigate2 URL & Request
Do While IE.readyState <> 4
DoEvents
Loop

Do While IE.busy = True
DoEvents
Loop

URL = "http://www.config.nissanusa.com/Dispatch.jsp"





For body = 0 To 1
If body = 0 Then
BodyStyle = "Sedan"
Else
BodyStyle = "Coupe"
End If

Request = "?changeModel=execute&" & _
"currentBodyType=" & Bodytype(body) & "&" & _
"_scrollPos=158&" & _
"locateConfig=true&" & _
"__action4=&" & _

"state_token=2%3A17%3Anissan%7Calt%7CALL%7C0%7CA4AAAAAAAAAA%7C%3A&" & _
".CurrentState=DealerMatchingVehiclesBrowse&" & _
"unselectVehicle=null&" & _
"tool=null&" & _
"sdealerID=" & dealerNumber & "&" & _
"sdealerContactable=true&" & _
"error_noResults=&"


Page = 0
Do
PageRequest = Request & "page=" & Page & "&"

IE.Navigate2 URL & PageRequest
Do While IE.readyState <> 4
DoEvents
Loop

Do While IE.busy = True
DoEvents
Loop


Call GetCarDetails(IE, DealerName, City, Distance, BodyStyle)

If IE.document.getelementsbytagname("B").Length <> 0 Then
Set PageNumbers = _
IE.document.getelementsbytagname("B") _
.Item(0).nextsibling

If Not PageNumbers Is Nothing Then
Page = Val(PageNumbers.innertext) - 1
End If
Else
Set PageNumbers = Nothing
End If
Loop While Not PageNumbers Is Nothing

RowCount = RowCount + 1
Next body
Loop
End With

End Sub



Public Enum States
NoState = 0
GetVehicleCount = 1
GetOption = 2
End Enum

Sub GetCarDetails(IE As Variant, _
DealerName As String, _
City As String, _
Distance As String, _
BodyStyle As String)

Dim Header As String
Dim DetailHeader As String

Set SearchResults = IE.document.getelementsbytagname("DIV")

State = NoState


CarRow = Sheets("Cars").Range("A" & Rows.Count).End(xlUp).Row
If CarRow = 1 Then
Sheets("Cars").Cells(1, "A") = "Dealer Name"
Sheets("Cars").Cells(1, "B") = "City"
Sheets("Cars").Cells(1, "C") = "Distance"
Sheets("Cars").Cells(1, "D") = "Body Style"
End If
DetailHeader = ""
For Each ClassItem In SearchResults
innertext = Trim(ClassItem.innertext)
Class = Trim(ClassItem.ClassName)
Select Case Class
Case "image_result-field"
CarRow = CarRow + 1
State = GetVehicleCount
CountRow = 0
Sheets("Cars").Cells(CarRow, "A") = _
DealerName
Sheets("Cars").Cells(CarRow, "B") = _
City
Sheets("Cars").Cells(CarRow, "C") = _
Distance
Sheets("Cars").Cells(CarRow, "D") = _
BodyStyle


Case "model-name"
HeaderCol = GetHeader("Model")
Sheets("Cars").Cells(CarRow, HeaderCol) = _
innertext
State = NoState
Case "vehicle-detail"
If InStr(innertext, ":") > 0 Then
Header = _
Trim(Left(innertext, InStr(innertext, ":") - 1))
HeaderCol = GetHeader(Header)
Detail = _
Trim(Mid(innertext, InStr(innertext, ":") + 1))
Sheets("Cars").Cells(CarRow, HeaderCol) = _
Detail

Else
HeaderCol = GetHeader(DetailHeader)
Sheets("Cars").Cells(CarRow, HeaderCol) = _
innertext
DetailHeader = ""
End If
State = NoState
Case "vehicle-detail-header"
DetailHeader = innertext
Select Case DetailHeader
Case "Packages and Options", _
"Accessories"

CountRow = 0
State = GetOption
Case Else
State = NoState
End Select
End Select

Select Case State
Case GetVehicleCount
'wait two rows
If CountRow = 2 Then
If innertext = "" Then
VehicleCount = 1
Else
VehicleCount = Val(innertext)
End If
End If
Header = "Number of Cars"
HeaderCol = GetHeader(Header)
Sheets("Cars").Cells(CarRow, HeaderCol) = _
VehicleCount
Case GetOption
If CountRow = 1 Then
HeaderCol = GetHeader(DetailHeader)
Sheets("Cars").Cells(CarRow, HeaderCol) = _
innertext
DetailHeader = ""
End If
End Select
CountRow = CountRow + 1

Next ClassItem
End Sub
Function GetHeader(Header As String)
With Sheets("Cars")
Set c = .Rows(1).Find(what:=Header, _
LookIn:=xlValues, lookat:=xlWhole)
If c Is Nothing Then
LastCol = .Cells(1, Columns.Count).End(xlToLeft).Column
.Cells(1, LastCol + 1).Value = Header
GetHeader = LastCol + 1
Else
GetHeader = c.Column
End If
End With
End Function
 
J

JP

Glad to hear it!

--JP

I solved the problem myself.  I found Excel makes an excellent debug package
when debugging HTML code.  You can easily write data to the spreadsheetfrom
a webpage like this

rowCount = 1
for each itm in IE.document.all
   Range("A" & RowCount) = itm.innertext
nextt itm
\
 
J

Joel

I have another problem I can't seem to solve. I have a SUBMIT button on a
webpage that I can't seemed to activate. the JAVA code for the button is
below. There are two buttons SUBMIT and RESET (end of Java Code). I set
the tag using

Set FORM = IE.document.getelementsbytagname("FORM")

I can't seem to perform the onsubmit action. I tried

FORM.onsubmit
FORM.Select
FORM.Activate

I've been able to set the selection box to "Fall 2008"
Set TermOptions = IE.document.getElementById("term_input_id")
TermOptions.Value = "200840"

Here is the Java.


<FORM ACTION="/pls/PROD/bwckgens.p_proc_term_date" METHOD="POST"
onSubmit="return checkSubmit()">
<INPUT TYPE="hidden" NAME="p_calling_proc" VALUE="bwckschd.p_disp_dyn_sched">
<TABLE CLASS="dataentrytable" SUMMARY="This layout table is used for term
selection." width="100%"><CAPTION class="captiontext">Search by Term:
</CAPTION>
<TR>
<TD CLASS="dedefault"><LABEL for=term_input_id><SPAN
class=fieldlabeltextinvisible>Term</SPAN></LABEL>
<SELECT NAME="p_term" SIZE="1" ID="term_input_id">
<OPTION VALUE="">None
<OPTION VALUE="200840">Fall 2008
<OPTION VALUE="200830">Summer II 2008 (View only)
<OPTION VALUE="200820">Summer I 2008 (View only)
<OPTION VALUE="200810">Spring 2008 (View only)
<OPTION VALUE="200750">Winter 2008 (View only)
<OPTION VALUE="200740">Fall 2007 (View only)
<OPTION VALUE="200730">Summer II 2007 (View only)
<OPTION VALUE="200720">Summer I 2007 (View only)
<OPTION VALUE="200710">Spring 2007 (View only)
<OPTION VALUE="200650">Winter 2007 (View only)
<OPTION VALUE="200640">Fall 2006 (View only)
</SELECT>
</TD>
</TR>
</TABLE>
<BR>
<INPUT TYPE="hidden" NAME="p_by_date" VALUE="Y">
<H3>OR</H3>
<TABLE CLASS="dataentrytable" SUMMARY="This layout table is used for date
selection." WIDTH="30%"><CAPTION class="captiontext">Search by Date Range
(MM/DD/YYYY):</CAPTION>
<TR>
<TD CLASS="delabel" scope="row" ><LABEL for=from_id><SPAN
class=fieldlabeltext>From:</SPAN></LABEL></TD>
<TD CLASS="dedefault">
<INPUT TYPE="text" NAME="p_from_date" SIZE="14" MAXLENGTH="12" ID="from_id">
</TD>
<TD CLASS="delabel" scope="row" ><LABEL for=to_id><SPAN
class=fieldlabeltext>To:</SPAN></LABEL></TD>
<TD CLASS="dedefault">
<INPUT TYPE="text" NAME="p_to_date" SIZE="14" MAXLENGTH="12" ID="to_id">
</TD>
</TR>
</TABLE>
<BR>
<INPUT TYPE="submit" VALUE="Submit">
<INPUT TYPE="reset" VALUE="Reset">
</FORM>
 
J

JP

Did you look at the link I posted earlier?

http://www.codeforexcelandoutlook.com/AutomateInetExplorer.html

The code for the submit button is

<INPUT TYPE="submit" VALUE="Submit">

So it would be something like

Dim btnInput As MSHTML.HTMLInputElement
Dim ElementCol As MSHTML.IHTMLElementCollection

Set ElementCol = appIE.Document.getElementsByTagName("INPUT")

For Each btnInput In ElementCol
If btnInput.Value = "Submit" Then
btnInput.Click
Exit For
End If
Next btnInput


HTH,
JP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top