1
votes

This needs to work with both Windows 7 and Windows 10. I'm converting a clients very manual Excel VBA based process to something linking MS Access via ODBC to his Pervasive database backend of his MRP program.

I found another thread where they were using Access VBA to unzip a file, but I can't post to that site, even though I have a login account, so I'm posting here:

https://answers.microsoft.com/en-us/office/forum/office_2007-access/how-do-i-extract-zip-files-through-ms-access/e3720f53-2413-409b-ad0b-bbfb67e823e4

The code used in that link is as follows. I haven't run it yet. Was just wondering how to incorporate an encrypted password value to get the desired result:

Sub ImportZippedFile(ByVal sZipFileName As Variant) 

  Dim oApp As Object
  Dim fileNameInZip As Variant

  Dim sFileNameFolder As Variant

  Dim vLocalZipName as Variant 

 vLocalZipName =sZipFileName

  'use system temp folder to extract zipped file to.
  sFileNameFolder = Environ("Temp") & "\Excel_Tmp\"

  'Extract the file into the newly created folder
  Set oApp = CreateObject("Shell.Application")

  'list all the file names within the zip file
  For Each fileNameInZip In oApp.Namespace(vLocalZipName ).items
    msgbox filenameinzip


    oApp.Namespace(sFileNameFolder).CopyHere _
      oApp.Namespace(vLocalZipName ).items.item(CStr(fileNameInZip))

  Next fileNameInZip

  Set oApp = Nothing
End Sub

However, the zip file in that example was evidently not password protected. My client has a directory full of password protected zip files. He uses Excel VBA and a database table that has the file names, and the encrypted password needed to unzip the file. His code calls WinZip from an Excel VBA shell out, and supplies the encrypted password as a parameter to WinZip so it can unzip the file.

His current code uses Winzip under Windows 7. I'm on Windows 10, and when I installed Winzip on my machine, it froze up File Explorer, and I could not view my subdirectories or directories. When I uninstalled WInzip, all was good again.

what code would allow me to unzip a file, using only Access VBA, if I had an encrypted password?

The encrypted password was generated by his Sage MRP program.

1

1 Answers

1
votes

I have covered zipping and unzipping "the Windows Explorer way" in my articles:

Zip and unzip files and folders with VBA the Windows Explorer way

but those have nothing to do with encrypted zip files as you can't do that natively.

However, you may be able to use the WinZip Command Line by shelling out to this, passing it a proper command line.