+ Reply to Thread
Results 1 to 6 of 6

Macro to download and import data

  1. #1
    Registered User
    Join Date
    08-21-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2013
    Posts
    50

    Macro to download and import data

    I'm currently looking for a way for Excel to automatically download an excel file and import the contents into my spreadsheet. In the past I have just used copy/paste, but that gets old very fast. Unfortunately I don't think web query is useful in this particular situation since the page only shows a fraction of all the data I need. Is it possible to use a macro that will import the download? I'm somewhat familiar with macros but unsure of where to start here.

    Here is an example of the data I need. The link to download is "Export Data" near the top.

    http://www.fangraphs.com/leaders.asp...on1=2014&ind=0

    Any ideas would be greatly appreciated.

  2. #2
    Forum Expert Tsjallie's Avatar
    Join Date
    09-15-2012
    Location
    NL
    MS-Off Ver
    2010, 2013, 2016
    Posts
    2,077

    Re: Macro to download and import data

    I don't think you can directly dowload a file from that website. The link behind "Export Data" runs a javascript generating the csv-file.
    I'm not sure whether it's possible to run that javascipt from a workbook. Guess the website's security won't allow you to.
    But if you can live with generating that csv-file, then the rest can be automatic.
    Importing teh csv can be done easily with a data connection.
    Cheers!
    Tsjallie




    --------
    If your problem is solved, pls mark the thread SOLVED (see Thread Tools in the menu above). Thank you!

    If you think design is an expensive waste of time, try doing without ...

  3. #3
    Registered User
    Join Date
    11-09-2009
    Location
    london, england
    MS-Off Ver
    Excel 2010
    Posts
    52

    Re: Macro to download and import data

    I was recently learning about downloading files from websites. I was able to automate IE to download the file from your given website. (However, I have yet to successfully create the same result by implementing resources such as XMLHTTP etc). chisox721, I hope I understand you correctly that this is part of a process you require in your macro.

    I have not implemented import as Tsjallie has answered it.

    Here is code. I hope it helps take you one step closer to your end solution. (BTW I'm still learning about CUIAutomation so I won't be much help on that.)
    Please Login or Register  to view this content.
    Please click * if the answer was helpful.

  4. #4
    Forum Expert Tsjallie's Avatar
    Join Date
    09-15-2012
    Location
    NL
    MS-Off Ver
    2010, 2013, 2016
    Posts
    2,077

    Re: Macro to download and import data

    Nice piece of code and it works.
    Assumed website security wouldn't allow it, but jumped to conclusions too soon.
    Now the download is automated, further importing the data can easily be done with a data connection (import from text)

  5. #5
    Registered User
    Join Date
    08-21-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2013
    Posts
    50

    Re: Macro to download and import data

    Hey guys-First off sorry for the delay in response, haven't had time to really dig into this until today. Thank you both for you suggestions, the code worked great Ducky. Now I just need to finish it off with the data import.

    Thanks again!

  6. #6
    Registered User
    Join Date
    08-21-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2013
    Posts
    50

    Re: Macro to download and import data

    One last question. Since I have multiple files that I need to import on a daily basis ie "Pitching", "Hitting", could there be an addition to the macro that would rename the downloaded file?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Download and import csv
    By excelcandy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-20-2014, 03:28 AM
  2. Download .xls from web then import it in a sheet
    By Endorfyne in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-26-2013, 07:42 AM
  3. Download data from web using macro please help
    By harishb63 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-04-2013, 04:29 AM
  4. Macro to download monthly stock data and to refresh that data with the macro
    By Frankdude in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-23-2011, 08:38 PM
  5. macro to download file from FTP and import to excel
    By yannipr in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-11-2008, 09:30 AM

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