The code below was created for that purpose. These code snippets do not create, delete or check for the existence of the files or folders which it uses. Check out the following code snippets to cover these areas:. Do not declare a String variable to hold the file paths, this will not work with the Shell. Declare a Variant variable to hold the file paths, this will ensure the code runs smoothly.
To call the procedure above the following code can be used within another procedure. Change the paths to be the folder you wish to zip and the name you want the zip folder to be called. Do you know the fastest way to learn foreign languages? It is to read, write, speak, and think in that language as often as possible.
Apart from speaking, programming languages are no different. The more you immerse yourself in that language, the faster you will pick it up. Therefore, what most people like you need is lots of examples that you can practice.
The book contains:. Unzipping is a much easier process and only requires the files to be copied from the zip file into the folder. Change the paths to be the name of the zip file you wish to unzip and the folder you wish to put the unzipped files into.
Create an empty zip file just using windows. Now open that file in Notepad. The section of code highlighted in blue informs windows this file is a zip file. The file is empty, so there is no code from other files in there. The code below is the line which inserts that same character string at the start of the file. As a result, Windows believes this is a zip folder. Application to copy the files.
Using the Shell. Application is similar to using the Windows environment, which is able to copy and paste files into a zip folder. By entering your email address you agree to receive emails from Excel Off The Grid. Do you need help adapting this to your needs? By taking the time to understand the techniques and principles in this post and elsewhere on this site you should be able to adapt it to your needs.
What next? Check out the latest posts:. I should also say that whilst the code snippets above will create the Zip file, all the folder paths must already exist. There are other snippets in the code library to create, delete and check for existence of folder and files. My variables are declared as variants as they should be , the paths are correct and folders are created. The purpose of this code is to ask for folder with zipped files and then extract all ZIP files into the existing path e.
Namespace UnzipedDirPath. CopyHere oApp. Namespace ZipPath. Can anyone help me please? I spent few hours solving why the hell I get the Run-time 91 error.
Thanks a lot! Hi Excel Off The Grid, points 1 and 2 are actually the way you proposed in my code. It has just been copied here in some strange way. I certainly have marks in the correct place as you proposed. I also tried to convert the type of variables by CVar like this: oApp. Namespace CVar ZipPath. After making the changes I noted above I was able to get files to unzip — I will send you the exact code.
Namespace unzipToPath. CopyHere shellApp. Namespace zippedFileFullName. If you define the strPath as a Variant rather than a String, it should work. Replace this: Dim strPath As String. Thanks a lot.. Application views it as a folder object rather than a String, which is why it needs to be a Variant. By passing a String between the procedures it remains as a String, therefore it is necessary to create it as a Variant initially.
Namespace FileNameZip. CopyHere oApp. Namespace FolderName. Count Application. Application" 'Copy the files to the compressed folder oApp. Application" oApp. Excel Articles Latest reviews Search Excel articles.
Log in Register. Search titles only. Search Advanced search…. Search forums. Log in. Install the app. If you forgot your password, you can reset your password. JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding. You are using an out of date browser. It may not display this or other websites correctly. You should upgrade or use an alternative browser. Using VBA to zip files. Thread starter DGelinas Start date Aug 9, DGelinas New Member.
A strange result with the missing "Set". Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Stack Gives Back Safety in numbers: crowdsourcing data on nefarious IP addresses. Featured on Meta.
0コメント