The statement isn't so "Doh" when you read the whole thing - the point being the file path and not the fact that they are all in a folder. Dave - I think I may have misunderstood and overreacted to your "Doh" post.
Reading over it, I think you may have been hitting your own forehead after realizing the files were all in a folder and didn't need the full code you had suggested. If so, I apologize for misreading it to read that I was some kind of idiot for saying the files were in a folder.
Yes, you did misunderstand and jump the gun. But, no problem, I just thought you would have known about ThisWorkbook. 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.
Extension can be another than "zip". Application" End If ' Extension of a cabinet file holding one or more files. FolderExists Destination Then ' Create the destination folder. FolderExists Destination Then ' For some reason the destination folder does not exist and cannot be created. If FileSystemObject. Namespace CVar Destination. CopyHere ShellApplication.
Items, OverWriteAll Contrary to the copying to a zip folder above , this code waits for the copying to finish, and will not continue until copying is done. Conclusion Armed with these two functions, you can control all basic zipping and unzipping from VBA. Files and download The complete module and an Access file is here: Compress 1. Compress I hope you found this article useful. Ask a related question. Geoffrey Smith. Commented: Thanks for putting this together. I tried implementing in Excel and there seems to be a difference in the way that the FileSystemObject.
OpenTextF ile function works. The parameter "ForWriting" is not valid in Excel; and need to specify 8 which allows for appending to file. Gustav Brock MVP. Most Valuable Expert This award recognizes tech experts who passionately share their knowledge with the community and go the extra mile with helpful contributions. Distinguished Expert This award recognizes someone who has achieved high tech and professional accomplishments as an expert in a specific topic.
Author Commented: Geoffrey, that is correct. Fortunately you can pass path of a folder inside the Zip to NameSpace directly and loop through it's files.
Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 2 years, 6 months ago. Active 2 years, 6 months ago.
Viewed times. Mikku Mikku 6, 2 2 gold badges 14 14 silver badges 36 36 bronze badges. This looks very like asking for an opinion "what should I do? Anyway sending big files with emails is a mess and should be avoided many companies have a 10mb or even 5mb limit. Actually why don't you just always exclude the "specific subfolder"? It works fine right now. This is an Extension to the process. The Process is like that only. We have to send the Zip, but if it exceeds 20mb then we can remove those files.
Show 1 more comment. Active Oldest Votes. Feel free to amend it to suit your needs Logic: Use.
0コメント