A
Alpineman2
For some reason I can't figure this out and need your help. Apprciate your
suggestions and help
I am having trouble extracting just the value of Name, Address, Phone.
Here is what I am trying to accomplish along with the code I've written thus
far. I have input to website via xls, but am having a tough time with the web
extraction.
An Excel database 'sheet11' consisting of properties and property contacts.
Each row contains a property and related contacts.
1. Extract the 1 or Many results (i.e. name, address, and phone number)
along with the corresponding Property "PIN", in 'sheet11'.
2. There may be more than one related contact for any one property, all
property related contacts are on the same row.
Example (xls sheet1)
PIN+lastname+firstname+city+state+zip+lastname2+firstname2+city2
1212123123, Doe, John, Chicago, IL, 60601, Smith, James, Plainfield
///////////////////////////////////////////////////////////////////////////////
Sub AnyWhoSearch()
'This project includes references to "Microsoft Internet Controls,
Microsoft HTML Object Library"
Sub YellowPageSearch()
'This project includes references to "Microsoft Internet Controls" and
'"Microsoft HTML Object Library"
'Variable declarations
Dim appIE As New InternetExplorer
Dim myURL As String
Dim myDoc As HTMLDocument
Dim strSearch As String
Dim newHour As Variant
Dim newMinute As Variant
Dim newSecond As Variant
Dim waitTime As Variant
Dim cn As Range
Dim cf As Range
Dim cc As Range
Dim cs As Range
'Dim cz As Range
'On Error GoTo errHandler
'Set starting range (first cell of data)
Set cn = Sheets("Sheet1").Range("b2")
Set cf = Sheets("Sheet1").Range("c2")
Set cc = Sheets("Sheet1").Range("d2")
Set cs = Sheets("Sheet1").Range("e2")
'Set cz = Sheets("Sheet1").Range("f2")
'Set starting URL and search string
myURL = "http://www.yellowpages.com/findaperson"
'loop through list of data
Do While cn.Value <> vbNullString
'Make IE navigate to the URL and make browser visible
appIE.Navigate myURL
appIE.Visible = True
'Wait for the page to load
Do While appIE.Busy Or appIE.readyState <> READYSTATE_COMPLETE
DoEvents
Loop
'Set IE document into object
Set myDoc = appIE.document
'Enter search string on form
myDoc.forms(0).qn.Value = cn.Value
myDoc.forms(0).qf.Value = cf.Value
myDoc.forms(0).qc.Value = cc.Value
myDoc.forms(0).qs.Value = cs.Value
'myDoc.forms(0).qz.Value = cz.Value
'Submit form
myDoc.forms(0).submit
'Wait for the page to load
Do While appIE.Busy Or appIE.readyState <> READYSTATE_COMPLETE
DoEvents
Loop
appIE.document.all.Item
For I = 0 To
appIE.document.getElementsByTagName("TD").Length - 1
Set s = appIE.document.getElementsByTagName("TD").Item(I)
txt = s.getAttribute("innerHTML")
cContact.Value = txt
Exit For
Next
Set s = Nothing
waitTime = Now + TimeValue("00:00:05")
Application.Wait waitTime
appIE.Refresh
Set cn = cn.Offset(1, 0)
Set cf = cf.Offset(1, 0)
Set cc = cc.Offset(1, 0)
Set cs = cs.Offset(1, 0)
'Set cz = cz.Offset(1, 0)
Loop
errHandler:
appIE.Quit: Set appIE = Nothing
End Sub
//////////
suggestions and help
I am having trouble extracting just the value of Name, Address, Phone.
Here is what I am trying to accomplish along with the code I've written thus
far. I have input to website via xls, but am having a tough time with the web
extraction.
An Excel database 'sheet11' consisting of properties and property contacts.
Each row contains a property and related contacts.
1. Extract the 1 or Many results (i.e. name, address, and phone number)
along with the corresponding Property "PIN", in 'sheet11'.
2. There may be more than one related contact for any one property, all
property related contacts are on the same row.
Example (xls sheet1)
PIN+lastname+firstname+city+state+zip+lastname2+firstname2+city2
1212123123, Doe, John, Chicago, IL, 60601, Smith, James, Plainfield
///////////////////////////////////////////////////////////////////////////////
Sub AnyWhoSearch()
'This project includes references to "Microsoft Internet Controls,
Microsoft HTML Object Library"
Sub YellowPageSearch()
'This project includes references to "Microsoft Internet Controls" and
'"Microsoft HTML Object Library"
'Variable declarations
Dim appIE As New InternetExplorer
Dim myURL As String
Dim myDoc As HTMLDocument
Dim strSearch As String
Dim newHour As Variant
Dim newMinute As Variant
Dim newSecond As Variant
Dim waitTime As Variant
Dim cn As Range
Dim cf As Range
Dim cc As Range
Dim cs As Range
'Dim cz As Range
'On Error GoTo errHandler
'Set starting range (first cell of data)
Set cn = Sheets("Sheet1").Range("b2")
Set cf = Sheets("Sheet1").Range("c2")
Set cc = Sheets("Sheet1").Range("d2")
Set cs = Sheets("Sheet1").Range("e2")
'Set cz = Sheets("Sheet1").Range("f2")
'Set starting URL and search string
myURL = "http://www.yellowpages.com/findaperson"
'loop through list of data
Do While cn.Value <> vbNullString
'Make IE navigate to the URL and make browser visible
appIE.Navigate myURL
appIE.Visible = True
'Wait for the page to load
Do While appIE.Busy Or appIE.readyState <> READYSTATE_COMPLETE
DoEvents
Loop
'Set IE document into object
Set myDoc = appIE.document
'Enter search string on form
myDoc.forms(0).qn.Value = cn.Value
myDoc.forms(0).qf.Value = cf.Value
myDoc.forms(0).qc.Value = cc.Value
myDoc.forms(0).qs.Value = cs.Value
'myDoc.forms(0).qz.Value = cz.Value
'Submit form
myDoc.forms(0).submit
'Wait for the page to load
Do While appIE.Busy Or appIE.readyState <> READYSTATE_COMPLETE
DoEvents
Loop
appIE.document.all.Item
For I = 0 To
appIE.document.getElementsByTagName("TD").Length - 1
Set s = appIE.document.getElementsByTagName("TD").Item(I)
txt = s.getAttribute("innerHTML")
cContact.Value = txt
Exit For
Next
Set s = Nothing
waitTime = Now + TimeValue("00:00:05")
Application.Wait waitTime
appIE.Refresh
Set cn = cn.Offset(1, 0)
Set cf = cf.Offset(1, 0)
Set cc = cc.Offset(1, 0)
Set cs = cs.Offset(1, 0)
'Set cz = cz.Offset(1, 0)
Loop
errHandler:
appIE.Quit: Set appIE = Nothing
End Sub
//////////