+ Reply to Thread
Results 1 to 12 of 12

Use VBA to download zip file and unzip the file?

  1. #1
    Forum Contributor
    Join Date
    09-10-2016
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    680

    Use VBA to download zip file and unzip the file?

    For example, if there is a zip file https://www.test.com/data/zip/sample.zip

    How can you use VBA to download the zip file then use VBA to unzip the file?

    Thanks.

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Use VBA to download zip file and unzip the file?

    Hi VAer,

    Here is a solution courtesy of Ron de Bruin: http://www.rondebruin.nl/win/s7/win002.htm

    Lewis

  3. #3
    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: Use VBA to download zip file and unzip the file?

    Hello VAer,

    I wrote this macro to download a zip file from a website or local storage. What I found was the URL for a zip file on a website opens a download page and then the server downloads the file to your download folder.

    The macro works on my local intranet and local storage with no problem. So, perhaps you will find it useful. The API code used is for 32 bit Windows and Office. If you experience a problem with the API call then I will need to provide you with the 64 bit API call.

    Download and Unzip File
    Please Login or Register  to view this content.
    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!)

  4. #4
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Use VBA to download zip file and unzip the file?

    Thanks a lot Mr. Leith for this awesome code ..
    I have tested it like that
    Please Login or Register  to view this content.
    but I got empty folder with no files ..
    Can you provide me with a valid lonk for a zip example file to make sure the code is working well? and why it is working but give me empty folder with no files?
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  5. #5
    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: Use VBA to download zip file and unzip the file?

    Hello Yasser,

    I encountered this problem as well. When downloading a sample zip file that I uploaded to my MediaFire account. The problem lies in how the server handles the link. When clicked, the server opens a new page which forces the user to click again to start the download.

    The API call will download files like pictures from a website with no problem. These files are directly accessible from the server. If the file cannot be directly accessed from the server then additional automation is required to negotiate with the host server to obtain the file.

    You can test the macro on a zip file on your hard drive. It will unzip the file to the folder path you provide.

  6. #6
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Use VBA to download zip file and unzip the file?

    Thank you very much for reply
    I had the direct download from the mediafire .. and tried another link and got the same empty folder
    Can you give me a working zip example file to test it?

    As for the zip file on my hard drive it is working perfect

  7. #7
    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: Use VBA to download zip file and unzip the file?

    Hello VBer,

    The failure of my first macro to download and unzip a file led me to dig into the Windows API a little deeper. I have created a new macro using a different API that works.

    Here is the new macro code and sub that will download a zip file from a website to your desktop.

    Please Login or Register  to view this content.

  8. #8
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Use VBA to download zip file and unzip the file?

    Hello Mr. Leith
    I have tested that and I encountered an error run-time '75' (path/file access error) at this line
    Please Login or Register  to view this content.

  9. #9
    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: Use VBA to download zip file and unzip the file?

    Hello Yasser,

    Try setting the download folder path to something other than your desktop.

  10. #10
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Use VBA to download zip file and unzip the file?

    That's great. Now it is working well
    But why the path of desktop failed .. Are there any settings that can be done to allow this path instead of the error access?

  11. #11
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Use VBA to download zip file and unzip the file?

    I have tested again and found that it succeeds now to download to desktop .. That's too weird
    Now it is working perfectly
    Thank you very much Mr. Leith

  12. #12
    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: Use VBA to download zip file and unzip the file?

    Hello Yasser,

    That is strange but I am happy to hear it is now working for you. If you discover any problems, let me know.

+ 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. Unzip file Automatically without search
    By Toadwart87 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-08-2014, 08:24 AM
  2. Unzip .gz file with VBA
    By chrisignm in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-04-2014, 07:14 PM
  3. [SOLVED] File Download Name assuming Thread Title as File Name Windows 2007
    By jaslake in forum Suggestions for Improvement
    Replies: 10
    Last Post: 03-19-2014, 01:07 PM
  4. Macro to Download csv file from a dynamic date based url to a specified file location
    By srimani202002 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-23-2014, 07:17 AM
  5. Unzip protected file using VBA
    By msherifam01 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-06-2013, 09:00 AM
  6. zip unzip .xlsx file error
    By IT Researcher in forum Excel General
    Replies: 2
    Last Post: 05-30-2013, 08:35 AM
  7. [SOLVED] Unzip file through VBA
    By amitdi in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-15-2012, 09:36 PM

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