+ Reply to Thread
Results 1 to 7 of 7

Build a macro that downloads files form a url and saves them as a new name

  1. #1
    Forum Contributor
    Join Date
    05-30-2013
    Location
    Isreal
    MS-Off Ver
    Excel 2010
    Posts
    191

    Build a macro that downloads files form a url and saves them as a new name

    Hello,
    I am looking to build a macro that downloads files form a url and saves them as a new name.

    I would like to save each url in my local computer in the path
    C:\test\
    the name for the first photo would be URL1 the second URL2.
    I would like to save each url in my local computer in the path
    C:\test\url1.jpg
    C:\test\url2.jpg


    You can find the sample spreadsheet at the following link:
    https://drive.google.com/file/d/1ATY...ew?usp=sharing


    Any help on the matter would be appreciated.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: I am looking to build a macro that downloads files form a url and saves them as a new

    Hello starlev,

    I have added the macro below to the attached workbook. It downloads the two files to the specified directory.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Contributor
    Join Date
    05-30-2013
    Location
    Isreal
    MS-Off Ver
    Excel 2010
    Posts
    191

    Re: Build a macro that downloads files form a url and saves them as a new name

    Thank you
    I will look into it an update if it works.

  4. #4
    Forum Contributor
    Join Date
    05-30-2013
    Location
    Isreal
    MS-Off Ver
    Excel 2010
    Posts
    191

    Re: Build a macro that downloads files form a url and saves them as a new name

    Thank you for your macro it seems to work:

    I have a little bit of understanding in VBA however I do not understand how your code connects to the Internet.

    I am assuming that the function Internet GetFile is the one that is connecting to the Internet.
    And that all the Const are some kind of ports.
    I will appreciate if you can explain more how this works.

    Also I would like to be able to resize photos if the resolution is smaller then 800 x 800 pixels to 825 x 825 however when I resize I would like to keep the original ratio but that at least the length and height are equal or bigger than 825 pixels.


    I was playing around with your code and I made it a bit more flexible.
    I added another macro called " Main_module"

    It has a macro Main_save_files
    I added the following options:
    1.VBA builds a folder name based on the SKU name.
    2. I built a loop that can work with multiple SKU'S
    I am attaching a workbook with all the new code.

    You can also find the code that builds folders here:


    Please Login or Register  to view this content.
    And the code the code that downloads the photos here
    Please Login or Register  to view this content.

    Thank you again for your help.

  5. #5
    Forum Contributor
    Join Date
    05-30-2013
    Location
    Isreal
    MS-Off Ver
    Excel 2010
    Posts
    191

    Re: Build a macro that downloads files form a url and saves them as a new name

    I forgot to attach to the previous post the spreadsheet

    You can find it at the following link:

    https://drive.google.com/file/d/1des...ew?usp=sharing

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Build a macro that downloads files form a url and saves them as a new name

    Hello starlev,

    Thanks for sharing your updated code. To answer your question about the internet connection, it is done by calling the Widows API (Application Program Interface) function OpenInternet and the file is downloaded using the Windows API function URLDownloadToFile. Both of these functions are low level system calls. If you are not familiar with how these calls operate, do not try to change them in the code. You can crash Excel or even the computer. The Const (Constant declaration keyword) provides the API calls with predefined values needed for execution or error detection and helps make the code more readable.

  7. #7
    Forum Contributor
    Join Date
    05-30-2013
    Location
    Isreal
    MS-Off Ver
    Excel 2010
    Posts
    191

    Re: Build a macro that downloads files form a url and saves them as a new name

    Hi Leith,
    The API that connects to the Internet I understand from you it is not a built functionality form VBA it is rather a Windows compartment.
    What do you suggest I search on Google in order to find more information about this topic?


    In my previous thread I requested to modify the code.

    Also I would like to be able to resize photos if the resolution is smaller then 800 x 800 pixels to 825 x 825 however when I resize I would like to keep the original ratio but that at least the length and height are equal or bigger than 825 pixels.


    Thank you for your help.

+ 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. [SOLVED] Macro to report and save .xlsx files only saves under 500 from less then 1000
    By Groovicles in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 08-29-2016, 03:20 PM
  2. Macro saves .xls files
    By Berna11 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-23-2016, 10:04 AM
  3. [SOLVED] Macro saves .xls files
    By Berna11 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-23-2016, 06:56 AM
  4. Macro that Opens files, updates links, saves and closes file
    By dandavis1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-09-2011, 04:28 AM
  5. Form button controlled macro that merges data from rows into Word & saves them
    By a.mack123 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-18-2010, 07:42 PM
  6. Macro to delete csv files in downloads folder
    By prontrad in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-18-2009, 06:48 AM
  7. build a macro that saves & names a file with the current day's date
    By mariusescu in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-09-2008, 10:22 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