Results 1 to 2 of 2

VBA to scrape data from website

Threaded View

  1. #1
    Registered User
    Join Date
    01-16-2012
    Location
    Dallas
    MS-Off Ver
    Excel 2007
    Posts
    1

    Question VBA to scrape data from website

    I am pretty new to VBA, but am trying to write a data scraper to pull information from a website and import it into an excel workbook. I had some help getting started but am coming across a few errors that I cannot figure out.

    1. run-time error 1004: application-defined or object-defined error

    If I comment out this error, I get to this:

    2: run-time error 1004: unable to open http://... the internet site reports that the item you requested could not be found.
    (But when I go to the exact same URL in explorer it opens fine.)

    
    Sub Master()
    Dim i, j As Double
    
    'set calc to manual
    Application.Calculation = xlManual
    Application.ScreenUpdating = False
    'set range of zips to run
    Sheets("Control").Select
    ActiveSheet.Calculate
    j = Range("C7").Value
    n = Range("C6").Value
    For i = n To j
    'save the workbook every 500 to prevent freeze and loss of progress
    x = i Mod 500
    If x = 0 Then
    ActiveWorkbook.Save
    End If
    
    'refresh screen to show % progress made
    Sheets("Control").Select
    Application.ScreenUpdating = True
    
    'set new team code
    Range("C6").Value = i
    ActiveSheet.Calculate
    
    Application.ScreenUpdating = False
    Call GetData
    Call CleanData
    Call UpdateZipDist
    
    Next i
    End Sub
    
    Sub GetData()
    'this procedure pulls the data from the website for a given URL
    Sheets("Control").Select
    ActiveSheet.Calculate
    strURL = Range("F10").Value
    Sheets("Web").Select
    Cells.Select
    Selection.QueryTable.Delete
    Selection.ClearContents
    Range("A1").Select
    'get data: web
    With ActiveSheet.QueryTables.Add(Connection:=strURL, Destination:=Range("$A$1"))
    .Name = "GetWebData"
    .FieldNames = True
    .RowNumbers = False
    .FillAdjacentFormulas = False
    .PreserveFormatting = True
    .RefreshOnFileOpen = False
    .BackgroundQuery = True
    .RefreshStyle = xlInsertDeleteCells
    .SavePassword = False
    .SaveData = True
    .AdjustColumnWidth = True
    .RefreshPeriod = 0
    .WebSelectionType = xlEntirePage
    .WebFormatting = xlWebFormattingNone
    .WebPreFormattedTextToColumns = True
    .WebConsecutiveDelimitersAsOne = True
    .WebSingleBlockTextImport = False
    .WebDisableDateRecognition = False
    .WebDisableRedirections = False
    .Refresh BackgroundQuery:=False
    End With
    
    End Sub
    Thanks in advance to any helpers
    Last edited by jdub22cb; 01-16-2012 at 02:54 PM.

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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