Monday, June 12, 2017

Extracting filenames within a given zip file

Sub ListZipDetails()
  Dim R As Long, PathFilename As Variant, FileNameInZip As Variant, oApp As Object
  PathFilename = Application.GetOpenFilename("ZipFiles (*.zip), *.zip")
  If PathFilename = "False" Then Exit Sub
  R = Cells(Rows.Count, "A").End(xlUp).Row
  Set oApp = CreateObject("Shell.Application")
  For Each FileNameInZip In oApp.Namespace(PathFilename).Items
    R = R + 1
    Cells(R, "A").Value = FileNameInZip & "  (" & PathFilename & ")"
  Next
  Set oApp = Nothing
End Sub
NOTE: As written, this code will not iterate through folders inside of the zip.

No comments:

Post a Comment