Import HTML code into Excel

J

josuegm

Hello guys,

Does anybody have any idea how can I pick html code from a webpage, and
paste into excel, line by line? The link from the webpage is a
variable, so I will get the information right from the web. All I need
is that:

Excel picks up the variable "link";

Get the html code from the "link" url, and place, line by line into
Excel as TEXT.

Could anybody help me?? PLEAAASSSE :)
 
J

Jake Marx

Hi josuegm,
Does anybody have any idea how can I pick html code from a webpage,
and paste into excel, line by line? The link from the webpage is a
variable, so I will get the information right from the web. All I need
is that:

Excel picks up the variable "link";

Get the html code from the "link" url, and place, line by line into
Excel as TEXT.

This should work:

Public Function gsGetHTML(rsURL As String) As String
Dim x As Object

Set x = CreateObject("Microsoft.XMLHTTP")

With x
.Open "GET", rsURL
.send
Do Until .ReadyState = 4
DoEvents
Loop
gsGetHTML = .ResponseText
End With

Set x = Nothing
End Function

Sub Demo()
Dim sHTML As String
Dim vHTML As Variant
Dim lRow As Long

sHTML = gsGetHTML(Range("A1").Value)
vHTML = Split(sHTML, vbCrLf)
For lRow = 2 To UBound(vHTML) + 2
Cells(lRow, 1).Value = vHTML(lRow - 2)
Next lRow
End Sub

Just put a URL in A1 and execute Demo(). There's no error handling, so you
may want to add some in (or at least check the validity of the URL).

--
Regards,

Jake Marx
www.longhead.com


[please keep replies in the newsgroup - email address unmonitored]
 

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