Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Opening a file win a zip file
Sandra Truax 
         
2 years ago
I'm hoping someone can help me with this. I've been trying to write VBA to open file 01.mp4 that is inside d:\1012.zip, preferably withouth extracting all the files. I have not been able to figure it out, and I can't even get my code right to extract to D:\TempFolder so I can open it from there.

This is my critea for the path and file name.

' Path to the zip file
Dim zipPath as string
zipFileName = "D:\" & TempVars!Website & ".zip"

' Path to extract to
Dim zipDestination as string
zipDestination = "D:\TempFolder"

' File to Open
Dim FileToOpen as string
FileToOpen = TempVars!NoteLinkText
Kevin Yip  @Reply  
     
2 years ago
The VBA code to do that is complicated.  But a third-party utility, like 7-Zip, that supports command-line options can do this with just one line of code.  To unzip a file with 7-Zip, the command is simply:

    7z e d:\1012.zip "file 01.mp4" -r

The "-r" option at the end looks for the file "recursively," which means it will find your file even if it is nested deep inside subfolders.  To do that with VBA would be exceedingly complicated, even if you knew the complete folder structure of the zip file.

To use the above command in VBA, use the Shell function:

    Shell "7z e d:\1012.zip ""file 01.mp4"" -r"

P.S. WinZip, which must be familiar to the older users here, also supports command-line options.
Sandra Truax OP  @Reply  
         
2 years ago
Thank you Kevin!
Alex Hedley  @Reply  
           
2 years ago
Are you trying to replicate the steps you'd do in Explorer?
When you double click on a zip it is actually decompressing it, albeit temporarily, until you actually say extract.

You can prob do it with VBA, but I'd need to look it up.
You can do it with PS or .NET
Another option is using 7zip cli
Sandra Truax OP  @Reply  
         
2 years ago
Hi Alex, I have the Tech Help videos saved in on my computer, and I zip them along with the database and the webpage in a file by the four digit code of the video (e.g. 1012).  Thin in access, I have notes of what the video is about, so if I want to rewatch it I normally use his shellEx command to open the zip file then click on the video to watch it.  I was trying to save a step and just be able to click a button and it play the video and since I can put "D:\Computer Learning Zone\1012.zip\01.mp4" in the Windows explorer search and it opens the video, I thought it would be an easy task in Access to do the same thing. I'm starting to think that was definitely not true. LOL
Richard Rost  @Reply  
          
2 years ago
I have code that I use to Zip and Unzip files. It uses PowerShell (which comes with Windows). I've been meaning to put this in a TechHelp video. Here's the code. I'll elaborate on it more soon...

DetailsSub ZipFolder(ZipFilePath As String, FolderToZip As String)

    Dim PSCommand As String, WinCommand As String
        
    PSCommand = "Compress-Archive -Path """ & FolderToZip & "\*"" -DestinationPath """ & ZipFilePath & """ -Force"
    WinCommand = "powershell -Command """ & PSCommand & """"
    shell WinCommand, vbNormalFocus
    
End Sub

Sub UnzipFolder(ZipFilePath As String, FolderToUnzipTo As String)

    Dim PSCommand As String, WinCommand As String
    
    PSCommand = "Expand-Archive -Path """ & ZipFilePath & """ -DestinationPath """ & FolderToUnzipTo & """ -Force"
    WinCommand = "powershell -Command """ & PSCommand & """"
    shell WinCommand, vbNormalFocus
    
End Sub


Richard Rost  @Reply  
          
2 years ago
So for example, you'd call it like this:

ZipFolder "C:\Users\amicr\Desktop\DB\MyZip.ZIP", "C:\Users\amicr\Desktop\DB\MyFolder"

That will create MyZip.ZIP and add all of the files in MyFolder. To Unzip it...

UnzipFolder "C:\Users\amicr\Desktop\DB\MyZip.ZIP", "C:\Users\amicr\Desktop\DB\NewFolder"

Now you've got the same files in NewFolder.

Yes, it's possible to extract/add individual files, but I've never needed to do that, so you're on your own for that one. :)
Sandra Truax OP  @Reply  
         
2 years ago
Thanks Richard!  And I thought you would be up for a challenge of looping thru all the files in a zip file and opening one up specific file without having to extract it! LOL  

I'll make this work.  Thanks again to all y'all for your assistance.
Richard Rost  @Reply  
          
2 years ago
I'm sure it could be done... but this works and is easier. LOL.

I dropped it in the Code Vault: Zip Unzip

I've also got a "shell and wait" version around here somewhere too, where VBA waits until the script is finished and gets the error level.

Video coming soon.
Richard Rost  @Reply  
          
2 years ago
Before you go to far with this code, I found my BETTER stash of code that handles Zip/Unzip without using PowerShell... and you can unzip a specific file or type of files (like all .DOC files). Coming shortly...
Richard Rost  @Reply  
          
2 years ago
Code is in the vault. Video coming later today. And, Sandra, you should be able to easily figure out how to modify my UnzipSpecificFiles code to give it an actual filename instead of just a file type. Easy string manipulation.
Richard Rost  @Reply  
          
2 years ago
In fact, looking over it, if you give it a specific filename, it should work.
Richard Rost  @Reply  
          
2 years ago
Yep. It did. No need to modify it.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/6/2026 5:20:24 AM. PLT: 1s