1. #1
    Nick@SI
    Nick@SI's Avatar Become A Pro!
    Join Date: 09-08-12
    Posts: 33
    Betpoints: 738

    Importing sdql into excel

    Was curious if anyone could help out I for the life of me can't seem to get trends found on Killersports or Sportsdatabase to import into excel. This pretty much last piece of automating my spreadsheet so be nice to have it done. If to difficult not a huge ordeal. Know they offer to save your personal trends and after a few the charge you a small fee, while it would be time saving. I don't mind doing the copy and pasting of the text if I have to. I've tried the importing it via typical web query through excel which gives me just that its trying to load but never get the teams I've also tried using VBA. Admittedly not the greatest when comes to VBA but can typically do enough to get myself what I want. Thanks in advance.

  2. #2
    stevenash
    stevenash's Avatar Moderator
    Join Date: 01-17-11
    Posts: 62,659
    Betpoints: 32267

    Referencing the ADO object library

    1. Start Excel. Open a new workbook and then save it as SQLExtract.xls.
    2. Start the Visual Basic Editor and select your VBA project.
    3. On the Tools menu, click References.
    4. Click to select the most recent version of the Microsoft ActiveX Data Objects Library check box.

    Creating the connection

    1. Insert a new module into the project.
    2. Create a new Sub procedure called DataExtract.
    3. Type or paste the following code:
      ' Create a connection object.Dim cnPubs As ADODB.ConnectionSet cnPubs = New ADODB.Connection' Provide the connection string.Dim strConn As String'Use the SQL Server OLE DB Provider.strConn = "PROVIDER=SQLOLEDB;"'Connect to the Pubs database on the local server.strConn = strConn & "DATA SOURCE=(local);INITIAL CATALOG=pubs;"'Use an integrated login.strConn = strConn & " INTEGRATED SECURITY=sspi;"'Now open the connection.cnPubs.Open strConn

    Extracting the data

    Type or paste the following code to extract your records:
    ' Create a recordset object.Dim rsPubs As ADODB.RecordsetSet rsPubs = New ADODB.RecordsetWith rsPubs ' Assign the Connection object. .ActiveConnection = cnPubs ' Extract the required records. .Open "SELECT * FROM Authors" ' Copy the records into cell A1 on Sheet1. Sheet1.Range("A1").CopyFromRecordset rsPubs ' Tidy up .CloseEnd WithcnPubs.CloseSet rsPubs = NothingSet cnPubs = Nothing

    Verifying that the code works

    1. Run the code.
    2. Switch to Excel and look at Sheet1 in the workbook to view the data.

  3. #3
    Nick@SI
    Nick@SI's Avatar Become A Pro!
    Join Date: 09-08-12
    Posts: 33
    Betpoints: 738

    Thank you very much. I will try this out tomorrow and update you with how I did.

Top