Hey there.
I wanted to make a code that automates extracting some specific data from web to excel,and i managed to do it thanks to resources online(found most of code,added/tweaked a bit)
Anyways,in an effort to better understand the VBA optimising,as well as to speed up the code itself,i was wondering if any kind of optimisation is doable on this code:
Formula:
Sub Updejt()
Dim i As Integer
Dim x As Integer
Dim sURL As String, sHTML As String, sAllPosts As String, link As String
Dim oHttp As Object
Dim lTopicstart As Long, lTopicend As Long
Dim TEMP As Worksheet
' aplication.ScreenUpdating = False /it wont work,gives me a out of range error
'i have to select the Sheet1 in order for all of this to work
'otherwise,it reports the script error 
Range("D11").Select
Do Until IsEmpty(ActiveCell)
link = ActiveCell.Value
Worksheets("TEMP").Activate
'i wouldn't allow me to use sURL = ActiveCell.Value
'so i had to go around it with 'link=activecell'
sURL = link
Set oHttp = CreateObject("MSXML2.XMLHTTP")
If Err.Number <> 0 Then
Set oHttp = CreateObject("MSXML.XMLHTTPRequest")
MsgBox "Error 0 has occured while creating a MSXML.XMLHTTPRequest object"
End If
On Error GoTo 0
If oHttp Is Nothing Then
MsgBox "For some reason I wasn't able to make a MSXML2.XMLHTTP object"
Exit Sub
End If
'Open the URL in browser object
oHttp.Open "GET", sURL, False
oHttp.Send
sHTML = oHttp.responseText
'Now extract all text within the hyperlinks <a href..>..</a>
'because they represent the topics
i = 1
lTopicstart = 1
lTopicend = 1
Do While lTopicstart <> 0
i = i + 1
lTopicstart = InStr(lTopicend, sHTML, "<a href=", vbTextCompare)
If lTopicstart <> 0 Then
lTopicstart = InStr(lTopicstart, sHTML, ">", vbTextCompare) + 1
lTopicend = InStr(lTopicstart, sHTML, "</a>", vbTextCompare)
Worksheets("TEMP").Range("A2").Offset(i, 0).Value = _
Mid(sHTML, lTopicstart, lTopicend - lTopicstart)
sAllPosts = sAllPosts & Chr(13) & Mid(sHTML, lTopicstart, lTopicend - lTopicstart)
End If
Loop
'Clean up
Set oHttp = Nothing
'i wanted to use a "range(activecell.offset(0,2).value=range(status).value
'but it didnt accept it for some reason(i guess it cant be 'active cell')
Worksheets("Igraci").Activate
ActiveCell.Offset(0, 2).Select
ActiveCell.Value = Worksheets("TEMP").Range("status").Value
ActiveCell.Offset(1, -2).Select
Loop
'aplication.ScreenUpdating = true OFF untill i find a way to fix it
End Sub
Code does exactly what its supposed to.I can explain the use and purpose of it further if needed.
I was unable to specify directly what data i needed to take from a transfermarket page,so i loaded all hyperlink texts,then saw that the data i need appears at A30 cell,and took it 'manually".
Thanks in advance
Bookmarks