Тёмный

Wise Owl Answers - How do I unzip files using VBA? 

WiseOwlTutorials
Подписаться 208 тыс.
Просмотров 7 тыс.
50% 1

By Andrew Gould
Scriptable Shell documentation docs.microsoft.com/en-us/prev...)
If you'd like to help fund Wise Owl's conversion of tea and biscuits into quality training videos you can join this channel to get access to perks:
/ @wiseowltutorials
Or you can click this link www.wiseowl.co.uk/donate?t=1 to make a donation. Thanks for watching!
This video shows you how to use the Windows Shell object to unzip a folder with VBA. You'll learn how to reference the Microsoft Shell and Automation Controls library and create a new instance of the Shell class. You'll see how to reference folders using the Namespace method, how to apply the CopyHere method to a destination folder and use the Items method to return the contents of a zipped folder. You'll also see how to achieve the same results using either early-binding or late-binding techniques.
Chapters
00:00 The Question
00:29 Creating a New Shell Object
01:53 Referring to Folders using the Namespace Method
04:10 Unzipping Files with the CopyHere Method
05:28 Overwriting Existing Files
07:02 Tidying Up the Code
09:31 Changing from Early Binding to Late Binding
11:22 Taking Care with Data Types
Visit www.wiseowl.co.uk for more online training resources in Microsoft Excel, Microsoft Power BI, DAX, VBA, Python, Visual C#, Microsoft SQL Server, SQL Server Reporting Services SSRS, SQL Server Integration Services SSIS, Microsoft Access and more!

Опубликовано:

 

6 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 105   
@CeliaAlvesSolveExcel
@CeliaAlvesSolveExcel 2 года назад
Brilliant! Thank you for explaining all the little details. Very, very helpful. Thank you, again.
@WiseOwlTutorials
@WiseOwlTutorials 2 года назад
My pleasure Celia, thank you for watching!
@wayneedmondson1065
@wayneedmondson1065 2 года назад
Wow.. thanks Andrew! As usual, you go above and beyond the basic answer to fill in a lot of useful background and optional information and methodology to solve VBA challenges. Thanks for sharing this great technique :)) Thumbs up!!
@WiseOwlTutorials
@WiseOwlTutorials 2 года назад
Thanks Wayne! Glad you enjoyed it and thanks, as ever, for the comments!
@KawanExcel
@KawanExcel 2 года назад
this is another mind blowing from Andrew..... Thank you very much , Andrew
@WiseOwlTutorials
@WiseOwlTutorials 2 года назад
You're very welcome, thank you for watching!
@piotrkuc8936
@piotrkuc8936 2 года назад
Such a great lesson! I truly adore the way you teach.
@WiseOwlTutorials
@WiseOwlTutorials 2 года назад
Thank you Piotr!
@KM-co5mx
@KM-co5mx 2 года назад
Thank you! I really appreciate how you explain things and show/demonstrate the what and why.
@WiseOwlTutorials
@WiseOwlTutorials 2 года назад
Glad you liked it, thanks for watching!
@marcelofreitas4593
@marcelofreitas4593 2 года назад
Hello, Andrew! I'm so grateful to you because you answered my question in so many details! Now, it's time to improve my routine. God bless you!
@WiseOwlTutorials
@WiseOwlTutorials 2 года назад
My pleasure Marcelo, happy to hear that it helped!
@simpabar1066
@simpabar1066 2 года назад
Love to see your face Andy, I hope you are always in good health with your family thanks for video tutorials😊👍👍🙏
@WiseOwlTutorials
@WiseOwlTutorials 2 года назад
Thank you Sim and the same to you and your family!
@hadibq
@hadibq 2 года назад
greatly explained! thanks for the tip for the Variant use. I guess that's the way to cope with the zero terminated strings within vba
@nikolaytkachenko4695
@nikolaytkachenko4695 2 года назад
Thanks for great lesson, you didn't miss no one of details i need, i mean "late binding", i like it more than "early binding", because it's easy for end users.
@WiseOwlTutorials
@WiseOwlTutorials 2 года назад
Thank you Nikolay!
@ncalc2261
@ncalc2261 2 года назад
Thank a lot, i keep getting error with the late binding method so searched for an early bind and found this video
@WiseOwlTutorials
@WiseOwlTutorials 2 года назад
Happy to hear that it helped, thanks for watching!
@MyAudioBookCompilation
@MyAudioBookCompilation 2 года назад
Very very nice. Thank you again.
@WiseOwlTutorials
@WiseOwlTutorials 2 года назад
You're very welcome, thanks for watching!
@KhalilYasser
@KhalilYasser 2 года назад
Awesome and brilliant my tutor. Thank you very much.
@WiseOwlTutorials
@WiseOwlTutorials 2 года назад
Thanks Yasser!
@RajKumar-on6oh
@RajKumar-on6oh 2 года назад
Genius! 🙆 Every details noted.
@WiseOwlTutorials
@WiseOwlTutorials 2 года назад
Thank you Raj!
@janezklun
@janezklun 2 года назад
The best there is, thank you Andy
@WiseOwlTutorials
@WiseOwlTutorials 2 года назад
You're too kind Janez, thank you!
@kolavithonduraski5031
@kolavithonduraski5031 2 года назад
plz more of these (small) Library examples 👍 (winapi, shell, internet explorer and so on) i know you did a lot of it in many videos. This small examples with your excelent explaination are in my opinion very helpful
@WiseOwlTutorials
@WiseOwlTutorials 2 года назад
Thank you, I'm happy to hear that you're finding the videos useful!
@vicenteantoniomagallanesju5289
@vicenteantoniomagallanesju5289 2 года назад
You are the best thanks.
@WiseOwlTutorials
@WiseOwlTutorials 2 года назад
Thanks Vicente!
@muhamadshehada4779
@muhamadshehada4779 2 года назад
NICE , Keep Going
@WiseOwlTutorials
@WiseOwlTutorials 2 года назад
Thanks!
@noneyabeezwax8865
@noneyabeezwax8865 26 дней назад
YOU are amazing!
@WiseOwlTutorials
@WiseOwlTutorials 26 дней назад
So are you! Thanks for watching!
@baludevunipalli
@baludevunipalli 2 года назад
THANKS.... Waiting for your pdf automation topics with VBA.
@WiseOwlTutorials
@WiseOwlTutorials 2 года назад
You're welcome, thank you for watching!
@youssefsedkey7616
@youssefsedkey7616 2 года назад
Thanks Andy very much. Question: When should I use Late binding, and when should I use early binding?
@WiseOwlTutorials
@WiseOwlTutorials 2 года назад
Hi Youssef! We have a video on this topic which you can see here ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-qmJPbub-D0E.html I hope it helps!
@elenacorchetevila9604
@elenacorchetevila9604 2 года назад
Thank you very much Andy! You are an incredible person. I am starting with VBA so I have another question related to this topic: when moving this files from a folder to another, how can I get to rename them ? I've looked through your videos but didn't find anything....
@WiseOwlTutorials
@WiseOwlTutorials 2 года назад
Hi Elena! As far as I know you'll have to rename the files separately from extracting them from the zip folder. There are lots of ways to do this, here's one: Sub RenameFiles() Dim sh As Shell32.Shell Dim MyFolder As Shell32.Folder Dim fi As Shell32.FolderItem Set sh = New Shell32.Shell Set MyFolder = sh.Namespace(ThisWorkbook.Path & "\Unzipped Files") For Each fi In MyFolder.Items fi.Name = "Some new text " & fi.Name Next fi End Sub You might also find this video on working with files and folders helpful ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-zHJPliWS9FQ.html I hope it helps!
@KM-co5mx
@KM-co5mx 2 года назад
Question please... What if you have multiple .zip files in the folder along with other file types... How would you loop thru and unzip only the .zip files? Thank You! I'm struggling with this. I figured it out... using a combination of watching you Files & Folders video and this one. Thank You again. You're Awesome!
@WiseOwlTutorials
@WiseOwlTutorials 2 года назад
And I was just about to post the link to that video :D happy to hear that you found the solution!
@selwyn_art
@selwyn_art 2 года назад
How can I rename the extracted file? I want to use this code in a folder that contains different zip folders but all of them comes with files with the same name, I want o keep all of them instead of overwriting
@PankajNegi007
@PankajNegi007 Год назад
Thanks Andrew Sir for sharing unique tricks. sir my question is how convert any folder in zip file?
@markbocsor3704
@markbocsor3704 2 года назад
Thank you Andrew, I could again learn something new and it was so well explained. Just a question: is there a solution for this also with file system object class?
@WiseOwlTutorials
@WiseOwlTutorials 2 года назад
You're welcome Mark! I don't think using the file system object class works in this case. The Folder class in the Scripting Runtime library doesn't allow you to reference a zip file as a folder, while the Folder class in the Shell Controls and Automation library does. I hope that helps!
@markbocsor3704
@markbocsor3704 2 года назад
@@WiseOwlTutorials Thank you Andrew
@WiseOwlTutorials
@WiseOwlTutorials 2 года назад
@@markbocsor3704 No problem Mark!
@GSTPALGHAR
@GSTPALGHAR Год назад
Hi Wise Owl. I have been using your guidance to save lot of time (and stress) in my office. Today also I have come across a particular problem that I don't find perfect solution for. I have 60 monthly zip files of 5 years in one folder. I want to extract all files to specific year folder to which they belong. every file name has month and year in it like (***_201707) denotes July 2017. In my template, I use 12 rows and year dropdown to check whether all the files exists or not. I want excel to extract those specific 12 files that I selected in dropdown. Can you help?
@user-wm1ob3vs2t
@user-wm1ob3vs2t 2 года назад
Hello, i don't know if this is the place to ask but here i go. I have a bunch of pdf's that have a java script in them that expires the pdf's after a due date. What i have done so far was to manualy change my date in my computer to view them and then printed them as a pdf to save them. Problem is that i have several thousands of pdfs. When i tried a hyperlink in vba i got a warning both from excel an from adobe. I then tried shell(). I'm sure there is a more elegant solution, hope i could get some directions on how to approach this, thanks
@WiseOwlTutorials
@WiseOwlTutorials 2 года назад
Hi! I'm sorry I don't have any good ideas for solving that problem.
@yanal1022
@yanal1022 Год назад
Hi there it gives an error for me. Unzipped file contains xlsm. - error on object doesnt support property or method
@manoj0790
@manoj0790 2 года назад
Thanks Andrew. Is there a way to unzip password-protected Zip?
@WiseOwlTutorials
@WiseOwlTutorials 2 года назад
Hi, sorry I don't know!
@sabarathinam9041
@sabarathinam9041 2 года назад
Hi bro - You are doing a Great Job I am in need of little suggestion Can we take screenshot of captcha and display it in Input Box in vba??
@WiseOwlTutorials
@WiseOwlTutorials 2 года назад
You can take a screenshot in Selenium easily enough. You can't paste a screenshot into an InputBox though.
@tejamarneni
@tejamarneni 2 года назад
Thank you Andrew for the amazing tutorial. Can you please make a video on creating PDF files using VBA. By the way, I guess this week is going to be pretty busy in Manchester because of Cricket and Football. :P
@WiseOwlTutorials
@WiseOwlTutorials 2 года назад
Hi Ravi! You're probably right about Manchester, I'll be avoiding the city centre! I don't have much to offer on the subject of constructing PDF files other than the videos we already have on saving workbooks as PDFs. I'm guessing you mean something more complicated than that?
@tejamarneni
@tejamarneni 2 года назад
@@WiseOwlTutorials I didn't know that you already made videos on that topic. My bad. Thank you so much Andrew.
@WiseOwlTutorials
@WiseOwlTutorials 2 года назад
@@tejamarneni No problem, there are so many videos that even I forget which ones I've made!
@dmbalzer
@dmbalzer 2 года назад
@@WiseOwlTutorials I have had success developing a python program using the PYPDF2 library, and creating a standalone executable with it that accepts arguments such as the path to the files you want to say join, then calling it from VBA using the shell() command with vba generated arguments. Wiseowl has started a python series of videos and could possibly be a topic explored there.
@user-yv5eu1wm8s
@user-yv5eu1wm8s Год назад
Hi... I wanted to take a zip file name from a Cell Value... how can I add that one in this code ? thanks
@WiseOwlTutorials
@WiseOwlTutorials Год назад
Hi! You can return the value of a cell by saying, for example Range("A1").Value or Range("A1").Text I hope it helps!
@celiabucsa6417
@celiabucsa6417 10 месяцев назад
Hello! I had something similar and it worked perfectly until now. Recently I had a version upgrade of Windows to Windows 11. Could this be the reason? I have tried with your code - exactly the same- and still does not work. No error, just that the unzip location remains empty. Thank you.
@WiseOwlTutorials
@WiseOwlTutorials 10 месяцев назад
Hi! I don't think that it's a Windows 11 issue, I've just copy-pasted the same file to a Windows 11 machine and it works in the same way. I'm sorry, I'm not sure what the problem is. Are all your folder paths the same after the upgrade to Windows 11?
@celiabucsa6417
@celiabucsa6417 10 месяцев назад
Yes, the folders are the same. There îs Something different in Windows11 wh 0 0:07 :07 en I unzip in Explorer, șo probably there is some difference in settings. I have 'cheated' by unzipping in Explorer and then using the rest of the macro. Thank you for trying.
@WiseOwlTutorials
@WiseOwlTutorials 9 месяцев назад
@@celiabucsa6417 I'm glad you have a workaround but I'd love to hear if you find the root of the problem!
@shamruthithulasiraman2099
@shamruthithulasiraman2099 11 месяцев назад
Is there any alternative for shell.namespace ...I'm getting an error when the zip path is too long and I couldn't open the zip..it is throwing an error
@WiseOwlTutorials
@WiseOwlTutorials 11 месяцев назад
I don't know of an alternative, sorry!
@philmillington5025
@philmillington5025 2 года назад
HI Andy Thanks for the video on Shell32.Shell functions very interesting to say the least. Is it possible to list the Files and Folders using the Shell? i.e. … recusing etc. Kind Regards Phil
@WiseOwlTutorials
@WiseOwlTutorials 2 года назад
Hi Phil! You can certainly loop through the items in the zip, see Example 2 here www.rondebruin.nl/win/s7/win002.htm As for looping recursively within a zipped folder, I'm not sure!
@philmillington5025
@philmillington5025 2 года назад
Thanks Andy will give this code a run over the next few days. Thank for taking the time to reply. I have made a note of the web site Ron de Bruin Excel Automation looks very interesting. Keep up the good work, your videos are the best by far Regards Phil@@WiseOwlTutorials
@WiseOwlTutorials
@WiseOwlTutorials 2 года назад
@@philmillington5025 Hi Phil! Yes, Ron's site is a great resource, I'm sure you'll find plenty of useful things there!
@harjeetsinghmakkar5177
@harjeetsinghmakkar5177 2 года назад
Great presentation. but in my case it just coped the zip files and not extracting the files. please help
@WiseOwlTutorials
@WiseOwlTutorials 2 года назад
Hi Harjeet, I'm sorry I don't know why that doesn't work for you.
@sunilmaharana1707
@sunilmaharana1707 Год назад
How to unlock and extract a password protected zip file through VBA excel??
@WiseOwlTutorials
@WiseOwlTutorials Год назад
Hi Sunil! Sorry, I don't know the answer to that!
@kashifkhanspecial
@kashifkhanspecial 2 года назад
Hi Andrew, I hope you are doing well and staying safe and healthy, I am in desperate need your expert help in a Excel vba error, there is an Excel utility that I build to create zip folder and then selected files by user will be moved into the zip folder, now I am facing a problem that vba code is not able to create a zip folder that have the file length more than 255 character, and I need to bypass that restriction because the filepath is dynamic and the filepath is generating by the concatenation of some columns value like product name, fund name etc, and I can't control to create a filepath less than 255 character because it is dynamic related to the product name, fund name etc. I am using below code to create a zip folder. Open zippedFileFullName For Output As #1 Print #1, Chr$(80) & Chr$(75) & Chr$(5) & Chr$(6) & String(18, 0) Close #1 Please help me :( Thanks Kashif
@WiseOwlTutorials
@WiseOwlTutorials 2 года назад
Hi Kashif! I'm sorry I don't know the exact answer to your question but these two links might help you stackoverflow.com/questions/14720710/is-there-a-way-for-dirpath-in-vba-to-handle-strings-longer-than-260 stackoverflow.com/questions/38432250/access-files-with-long-paths-over-260 I hope it helps!
@kashifkhanspecial
@kashifkhanspecial 2 года назад
Thanks Andrew for the reply, no worries, I am applying different approach first I will check that is the file name is longer than 255 character then I will create the zip file in the desktop then will move this file to the destination folder and if the file name is not more than 255 character then will directly create the zip file in destination folder, this is what I am going to do. I read somewhere that if the file path is longer than 247 character then you can add \\?\ to the beginning with the file path string and filesystem object can handle this and we can apply some methods of filesystem object against the target file like we can check fileexists etc, and unfortunately we can’t creat zip file with filesystem object. Note: if the file path is longer than 247 character then we can’t use Dir or other function to check the file existance in the folder, except use filesystem object and put \\?\ to the beginning of the file path then use filesystem object to check of the file is exist. Note: I am using Shell function to move the file to the destination folder if the file is longer than 255 character. Thanks again for the reply. Kashif
@WiseOwlTutorials
@WiseOwlTutorials 2 года назад
@@kashifkhanspecial I hope you have success solving the problem!
@kashifkhanspecial
@kashifkhanspecial 2 года назад
Hi Andrew, this solution also could mot work, what is worked is that to overcome 255 character limit, at run time I am dynamically mapping the target network folder with a letter through the code and after zipping the file in the end of the code I am removing the mapping with the code and it is working perfectly. This is the perfect solution I found as per my knowledge to remove the 255 character limit for folder/file. Thanks Kashif
@WiseOwlTutorials
@WiseOwlTutorials 2 года назад
@@kashifkhanspecial Great, happy to hear you found a solution!
@tungvu3380
@tungvu3380 2 года назад
Hope you to have a video about manapulating datepicker popup on a website using vba. Many thanks.
@WiseOwlTutorials
@WiseOwlTutorials 2 года назад
Do you have a specific website as an example?
@tungvu3380
@tungvu3380 2 года назад
@@WiseOwlTutorials I search something on Google, then I use time range filter from one date to another date, maybe. Thanks in advance. Actually I need to get all transactions during a period of time on a inner website. I try to input dates from cells' value on Excel worksheet, but I can't close the datepicker popup before clicking on the submit button to export an output file. The popup covers the button entirely that results to an error if I try to click on that button
@WiseOwlTutorials
@WiseOwlTutorials 2 года назад
@@tungvu3380 It's tricky to offer help without access to the page you're using. Is your button part of a element? If so, you could try to get a reference to the form as a WebElement and apply the Submit method to it, rather than trying to click the button.
@tungvu3380
@tungvu3380 2 года назад
@@WiseOwlTutorials the button is in an input tag, so I search that button by FindElementsByTag with its index, then use Submit method instead of Click method but it doesn't work as I expect. Would you mind if I send an email with screenshots I took? Thank you very much.
@WiseOwlTutorials
@WiseOwlTutorials 2 года назад
@@tungvu3380 Hi, you need to apply the Submit method to the Form which contains the Input button, not to the Input button itself.
@surjitpal8959
@surjitpal8959 Год назад
How to do custom sorting using vba..
@WiseOwlTutorials
@WiseOwlTutorials Год назад
Hi Surjit! Here's an example assuming you have a list beginning in cell A1 with column A containing a column header followed by the values a, b, c, d, e With Sheet1.Sort .SortFields.Clear .SetRange Range("A1").CurrentRegion .Header = xlYes .SortFields.Add _ Key:=Range("A:A"), _ SortOn:=xlSortOnValues, _ Order:=xlAscending, _ CustomOrder:="e,a,c,d,b" .Apply End With I hope it helps!
@michaelpedersen5087
@michaelpedersen5087 5 месяцев назад
Have you ever made a video about how to zip files using vba?
@WiseOwlTutorials
@WiseOwlTutorials 5 месяцев назад
Hi! No sorry, we don't have a video on that.
@vinoth181988
@vinoth181988 2 года назад
Pls help me how to declare password within the macro while unzip
@WiseOwlTutorials
@WiseOwlTutorials 2 года назад
I don't think that you can provide a password using the technique shown in the video. Ron de Bruin has some examples using 7-Zip or WinZip to extract password protected files www.rondebruin.nl/win/section7.htm I hope it helps!
@vinoth181988
@vinoth181988 2 года назад
There is no code 😭😭
@vinoth181988
@vinoth181988 2 года назад
Related to extract password protected file using macro
@WiseOwlTutorials
@WiseOwlTutorials 2 года назад
@@vinoth181988 There is :D You need to click the link that says "Click here to open the txt file" on a page like this one www.rondebruin.nl/win/s7/win005.htm
@vinoth181988
@vinoth181988 2 года назад
@@WiseOwlTutorials thnks a lot for your support
@ivanlushin3962
@ivanlushin3962 Год назад
and how unrar rar files???
@WiseOwlTutorials
@WiseOwlTutorials Год назад
Sorry I don't know!
Далее
Китайка Шрек всех Сожрал😂😆
00:20
Это реально работает?!
00:33
Просмотров 3,6 млн
SPILLED CHOCKY MILK PRANK ON BROTHER 😂 #shorts
00:12
Unzip Zip File | 2021
6:42
Просмотров 2,5 тыс.
~/.dotfiles in 100 Seconds
13:54
Просмотров 413 тыс.
JPEG is Dying - And that's a bad thing
8:09
Просмотров 132 тыс.
The Easiest Way to Scrape Web Data with VBA
7:18
Просмотров 106 тыс.
Китайка Шрек всех Сожрал😂😆
00:20