• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA to web scrape multiple urls

That is so cool, but completely over my head. I couldn't even get past step one, references. Anyway we can do without? I have a similar code that uses a different concept (page number) I was trying to modify for my needs, but I haven't gotten anywhere with this either. I've attached a file with it.
 

Attachments

  • Test-macro SLS.zip
    67.1 KB · Views: 20
Code:
Sub Macro1()
'
' Macro1 Macro
'
'
  Sheets("Sheet1").Select
  Range("A1").Select
Dim i As Integer, myurl As String
i = 1
Do While i < 300000
myurl = "URL;http://catalog.bd.com/nexus-ecat/getProductDetail?productId=" & i & ""
 
 
 
  With ActiveSheet.QueryTables.Add(Connection:=myurl, Destination:=Range("$A$1"))
  .Name = shorturl
  .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
  .WebDisableDateRecognition = False
  .WebDisableRedirections = False
  .Refresh BackgroundQuery:=False
  End With
 
  Columns("A:J").Select
  Selection.Copy
  Range("K1").Select
  Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
  :=False, Transpose:=False
  Columns("A:J").Select
  Range("J1").Activate
  Application.CutCopyMode = False
  Selection.Delete Shift:=xlToLeft
  Columns("A:J").Select
  Selection.ColumnWidth = 20.01
  Columns("B:B").Select
  Selection.ColumnWidth = 20.01
  Rows("1:300").Select
  Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
 
  i = i + 1
 
Loop
 
 
End Sub


Here's what I got so far, and it works ok. How do I get it to only pull data from valid url strings ending between 200000-300000? Any advice, as always, is greatly appreciated.
 
For that large of numbers, don't Dim I as an Integer, which has a upper limit of about 32000. Define it as a Long.
Code:
Dim i as Long
That should solve the issue with big numbers.
 
Back
Top