jeudi 8 décembre 2016

macro to import website table(s) into excel

im really new to all things coding (academic/psychologist) and im trying to pull the data from this site to create my own local database (http://ift.tt/2ge2Qxn).

My method (I cant find a "list all" features) has been to query the uk postcode district i.e. AB1, see here ( http://ift.tt/2h8ZAb2) using the code i compiled from a few sources (see below) in VBA.

Sub GetCourseList()

Dim URL As String
Dim qt As QueryTable
Dim ws As Worksheet

Set ws = Worksheets.Add

URL = "http://ift.tt/2gdNF7A"

Set qt = ws.QueryTables.Add( _
    Connection:="URL;" & URL, _
    Destination:=Range("A1"))

With qt
    .RefreshOnFileOpen = True
    .Name = "CoursesFromWiseOwl"
    .FieldNames = True
    .WebSelectionType = xlAllTables
    .Refresh BackgroundQuery:=False
End With

End Sub

my issues are 3 fold:

  1. i want to repeat this for all 3000-odd uk postcode districts (i can get a list)
  2. i want to remove the extra lines it returns (if you run the code 1-22 and 548+, but this will differ per district)
  3. id like to compile all the data to 1 database, not 3000 seperate sheets.

the excel getdata/webquery/table 1 (using this URL http://ift.tt/2gdNF7A) does almost exactly what i want, except it only returns page1, but i havent been able to work out how to automate/stitch the code i want together!

can anyone help sort this out for me?

cheers

Seb

Aucun commentaire:

Enregistrer un commentaire