+ Reply to Thread
Results 1 to 1 of 1

Macro to loop through and fetch data from multiple websites

  1. #1
    Registered User
    Join Date
    04-25-2013
    Location
    perth, australia
    MS-Off Ver
    Excel 2011
    Posts
    22

    Macro to loop through and fetch data from multiple websites

    Hey guys,

    I am a bit of a rookie with VBA and need to import a bunch of data from approx 115 different webpages with a very predictably changing URL.

    Website: http...seas/1897.html

    where 1897 is year.

    I've simply recorded a macro of me doing it manually and want to edit the macro so it loops through for all webpages from year 1897-2013. Apart from the year changing, the URL remains identical. Additionally I would like to insert 1898 below 1897 all on the same worksheet, so that the data is sorted from oldest to newest. How do I create the loop? Below is my current code... Thanks!

    Sub Macro2()
    With ActiveSheet.QueryTables.Add(Connection:= _
    "URL;http...seas/1898.html", Destination:=Worksheets("Sheet3").Range("$A$1") _
    )
    .Name = "1897"
    .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
    Last edited by wishkey; 05-21-2013 at 10:59 PM.

+ Reply to Thread

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