Zip files vba access


















MrHans Registered User. Local time Today, Joined Jul 27, Messages Here is a link to an article by Gustav Brock, I didn't try it, but he writes very good code, so it should work. Local time Today, Joined Mar 5, Messages 1, June7 said:.

I only know how to do it with an external program called 7zip. MrHans said:. If you do use another app to zip files, make sure users receiving your zip can still open it. Number11 Member. Local time Today, Joined Jan 29, Messages Does any one know how to change this code to only run if the folder contains files?

Local time Today, Joined Oct 29, Messages 17, Number11 said:. You must log in or register to reply here. Similar threads G. Invalid procedure call or argument brows and attach file. Replies 23 Views Oct 28, Minty. Solved How to open a set of CSV files created on a certain date span? Replies 36 Views Sep 29, moke Replies 14 Views Have a question about something in this article?

You can receive help directly from the article author. Sign up for a free trial to get started. Start Free Trial. Log In. Web Dev. Experts with Gold status have received one of our highest-level Expert Awards, which recognize experts for their valuable contributions. Published: Updated: Edited by: Andrew Leniart. Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc.

In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here. Ease of use There are many uses for zip folders. If you are interested in this, please see: Handle cabinet files and folders with VBA the Windows Explorer way Zip and Unzip These two functions are included in the code and does just that in a way that - by default - matches the result as if you did it manually onscreen using Windows Explorer.

Code Both Zip and UnZip takes advantage of two standard Microsoft libraries found on any Windows machine: Microsoft Shell Controls And Automation Microsoft Scripting Runtime and both functions allow for early or late binding as you prefer, controlled by the constant EarlyBinding that you can adjust to your preference. If so, the current path is used. Gustav Brock.

Application" End If ' Mandatory extension of zip file. FileExists Path Then ' The source is an existing file. GetFile Path. FolderExists Path Then ' The source is an existing folder. GetFolder Path. ParentFolder Else ' The source does not exist.

Write ZipHeader. Close End With ' Resolve relative paths. With ShellApplication Debug. Print Timer, "Zipping started. Namespace CVar ZipTemp. On Error Resume Next ' Wait for the file to created. Do Until. Sleep 50 Debug. Print ". Print ' Resume normal error handling. On Error GoTo 0 Debug.

Print Timer, "Zipping finished. CopyHere CVar Path End With A problem here is, however, that after calling this, our code would just continue, while - as you know - zipping a lot of files can take some time, and we have some clean-up to do afterwards.

Loop inserts a tiny delay which will be repeated over and over until the zip folder is ready: With ShellApplication Debug. Easy cheesy! Lines wrap up the Step 2 — Exploration portion of our script, and all four of these lines revolve around creating the String that we will launch from the command line. If we were to Debug. Print our strCommand variable for the first run in this sheet, it would look like this:.

Step 3 — Execution takes place from line 39 to line 45, and it all revolves around the WshShell object, which is stored as wsh in our script. On line 39, we assign lngErrorCode which will be a number to the output of wsh. Run with three inputs:. If the command was successful, lngErrorCode will be 0 zero.



0コメント

  • 1000 / 1000