Extract Data from Web (URL)

Vishesh's picture
Here is a small piece of code to extract data from a web page. Pass the url and target range to the below function.
Sub ExtractUrl(strURL As String, rngTarget As Range)
    Dim wksCurrent As Worksheet
 
    Set wksCurrent = ActiveSheet
 
    With CreateObject("InternetExplorer.Application")
        '.Visible = True
        Application.StatusBar = "Extracting from: " & strURL
 
        .Navigate strURL
 
        'Set wait time to allow the url to load completely
        Call Application.Wait(Now + TimeValue("0:00:05"))
        Do Until .ReadyState = 4: DoEvents: Loop
 
        Application.Goto rngTarget
        .ExecWB 17, 2 '// SelectAll
        .ExecWB 12, 0 '// Copy selection
        rngTarget.Parent.Paste
        .Quit
    End With
 
    Application.StatusBar = False
 
    wksCurrent.Activate
    Set wksCurrent = Nothing
End Sub