Consulting

Results 1 to 3 of 3

Thread: Downloading data from webpage into Excel

  1. #1

    Downloading data from webpage into Excel

    Hi,

    Does anyone know whether it would be possible to download data directly into excel or as a txt/csv file from the following webpage?

    http://www.dol.gov/opa/media/press/eta/ui/current.htm

    Specfically I am only intrested in downloading the table under the section below.

    Thanks,

    Elvis

    UNEMPLOYMENT INSURANCE DATA FOR REGULAR STATE PROGRAMS

    WEEK ENDING
    March 28
    March 21
    Change
    March 14
    Year

    Initial Claims (SA)
    669,000
    657,000
    +12,000
    644,000
    389,000
    Initial Claims (NSA)
    594,464
    590,067
    +4,397
    601,193
    341,846
    4-Wk Moving Average (SA)
    656,750
    650,250
    +6,500
    650,000
    367,750

    Advance



    Prior1
    WEEK ENDING
    March 21
    March 14
    Change
    March 7
    Year

  2. #2
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Hi there,

    You could go by HTML table number if you wanted. Not sure how many tables you're wanting, but here are the first 5 tables via web query...

    [vba]Sub GrabHTMLTable()

    Dim wb As Workbook, ws As Worksheet
    Dim objWeb As QueryTable, iRow As Long, strURL As String
    Dim arrTables(1 To 5) As Byte, i As Long

    arrTables(1) = 9: arrTables(2) = 10: arrTables(3) = 11
    arrTables(4) = 12: arrTables(5) = 13
    strURL = "http://www.dol.gov/opa/media/press/eta/ui/current.htm"
    Set wb = ActiveWorkbook
    Set ws = wb.Worksheets.Add(after:=wb.Worksheets(wb.Worksheets.Count))
    iRow = 1
    For i = LBound(arrTables) To UBound(arrTables)
    Set objWeb = ws.QueryTables.Add(Connection:="URL;" & strURL, Destination:=ws.Cells(iRow, 1))
    objWeb.WebSelectionType = xlSpecifiedTables
    objWeb.WebTables = arrTables(i)
    objWeb.Refresh BackgroundQuery:=False
    objWeb.SaveData = True
    iRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row + 1
    Next i
    ws.Cells.EntireColumn.AutoFit

    End Sub[/vba]

    Let us know if that helps or not. It isn't too fast, because each table has its own web query.

    HTH

  3. #3
    or change
    [VBA]objWeb.WebSelectionType = xlSpecifiedTables [/VBA]

    to

    [VBA]objWeb.WebSelectionType = xlEntirePage[/VBA]

    for the ... "Entire Page" and then parse through it in Excel.

Posting Permissions

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