View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jake Marx[_3_] Jake Marx[_3_] is offline
external usenet poster
 
Posts: 860
Default Import HTML code into Excel

Hi josuegm,

josuegm wrote:
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]