Copying web pages onto Excel Spreadsheets using VBA
Below is a simple example of getting data grom a website. If I had the URL
address and the data yo want I can write a similar routine. There are lots
of tricks in getting this data and the more experience you have the easier it
is. I have helped a number of people get web data. they all have been
succesful and happy with the resutls. The more knowledgable you are with VBA
programming and HTML format the easier it is.
Sub GetZipCodes()
ZIPCODE = InputBox("Enter 5 digit zipcode : ")
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
URL = "http://zip4.usps.com/zip4/citytown_zip.jsp"
'get web page
IE.Navigate2 URL
Do While IE.readyState < 4 And _
IE.busy = True
DoEvents
Loop
Set Form = IE.document.getElementsByTagname("Form")
Set zip5 = IE.document.getElementById("zip5")
zip5.Value = ZIPCODE
Set ZipCodebutton = Form(0).onsubmit
Form(0).submit
Do While IE.busy = True
DoEvents
Loop
Set Table = IE.document.getElementsByTagname("Table")
Location = Table(0).Rows(2).innertext
IE.Quit
MsgBox ("Zip code = " & ZIPCODE & " City/State = " & Location)
End Sub
"kenrock" wrote:
Hi,
Attempts to code, in VBA, a means of copying a web page onto an Excel
sheet have been frustrating and inconclusive.
When I apply the "QueryTables.Add" approach using the URL, I get a
partial result but it does not include the data I wish to capture -
just static data.
If I use the "FollowHyperlink" approach, Internet Explorer is called
and the web page is displayed but I cannot see how to code in VBA,
"SellectAll" and "Copy" so that I can then "Paste" to the Excel
sheet. I have tried this approach in a manual manner using a list of
Hyperlinks and calling each Hyperlink, copying the web page and
pasting onto individual spreadsheets.
Can this be achieved using VBA?
TIA, Ken Rock
|