Results 1 to 2 of 2

Assing result from httpRequest to adequate cell,optimising the working code

Threaded View

  1. #1
    Registered User
    Join Date
    01-25-2013
    Location
    Bosnia and Herzegovina
    MS-Off Ver
    Excel 2010
    Posts
    35

    Assing result from httpRequest to adequate cell,optimising the working code

    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: copy to clipboard

    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
    Last edited by 4evra; 08-30-2013 at 02:51 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Optimising code
    By Gti182 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-10-2012, 11:44 AM
  2. optimising code, if cell is not empty then copy data from one column to another
    By rain4u in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-08-2012, 11:29 AM
  3. optimising & accelerating macro code
    By Gti182 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-05-2011, 06:56 AM
  4. Optimising code
    By mpower87 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-31-2011, 11:49 PM
  5. Help with optimising code
    By FrigidDigit in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-20-2005, 11:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1