Extract a single file from a Compressed Folder (Zip file)

P

Paul Martin

Hi guys

Given a certain criteria in a filename, I would like to
programmatically extract a single file from a zip file (compressed
folder) that may have one or many files in it. Can someone point me
in the right direction?

Thanks in advance

Paul Martin
Melbourne, Australia
 
P

Paul Martin

Thanks for the response, Ron. That looks like it might do what I want
it to, though it'll be a while before I can try it.

Paul
 
P

Paul Martin

Thanks Ron, that's working just fine. I'm using the line code you
commented out to select a specific file.

Paul
 
P

Paul Martin

I've been using the below code with success, but now it's failing at
oApp.Namespace(TEMP_FOLDER).CopyHere. I get a Windows (not VBA) error
saying "the file exists." The temp folder is in fact empty. Any
suggestions?

Private Sub LoopThruFileItems(ByVal varZipFullPath As Variant)
Dim oApp As Object
Dim objFile As Object
Dim strCSVFullPath As String

Set oApp = CreateObject("Shell.Application")
TEMP_FOLDER = Environ("USERPROFILE") & "\Desktop\TEMP\"

For Each objFile In oApp.Namespace(varZipFullPath).Items
If Left(objFile.Name, 6) = "int140" Then
' Copy required file item from zip to temp folder
oApp.Namespace(TEMP_FOLDER).CopyHere _
oApp.Namespace(varZipFullPath).Items.Item(objFile.Name)

' Extract data, then delete the file item extracted from
the zip file
strCSVFullPath = TEMP_FOLDER & objFile.Name
ExtractData strCSVFullPath
Workbooks(objFile.Name).Close False
Kill strCSVFullPath
End If
Next objFile
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top