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
Bookmarks