mcdhappy80
Registered User.
- Local time
- Today, 22:32
- Joined
- Jun 22, 2009
- Messages
- 347
I've found this Unzip Module on net and it works perfect. The only thing that bothers me is that after the unzip operation explorer window, where the files are stored, opens. How do I stop the window from opening?
Thank You.
Unzip Module:
Thank You.
Unzip Module:
Code:
Option Compare Database
Option Explicit
Declare Function OpenProcess Lib "kernel32" _
(ByVal dwDesiredAccess As Long, _
ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long
Declare Function GetExitCodeProcess Lib "kernel32" _
(ByVal hProcess As Long, _
lpExitCode As Long) As Long
Public Const PROCESS_QUERY_INFORMATION = &H400
Public Const STILL_ACTIVE = &H103
Public Function ShellAndWait(ByVal PathName As String, Optional WindowState)
Dim hProg As Long
Dim hProcess As Long, ExitCode As Long
'fill in the missing parameter and execute the program
If IsMissing(WindowState) Then WindowState = 1
hProg = Shell(PathName, WindowState)
'hProg is a "process ID under Win32. To get the process handle:
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, hProg)
Do
'populate Exitcode variable
GetExitCodeProcess hProcess, ExitCode
DoEvents
Loop While ExitCode = STILL_ACTIVE
End Function
'With this example you can browse to the zip file you want to unzip
'The zip file will be unzipped in a new folder in: Application.DefaultFilePath
'Normal if you have not change it this will be your Documents folder
'The name of the folder that the code create in this folder is the Date/Time
'You can also use a fixed path like :
'NameUnZipFolder = "C:\Users\Ron\TestFolder\" & Format(Now, "yyyy-mm-dd hh-mm-ss")
'Read the comments in the code about the commands/Switches in the ShellStr
'There is no need to change the code before you test it
Function A_UnZip_Zip_File_Browse(pNameUnzipFolder As String, pFileNameZip As String)
Dim PathZipProgram As String, NameUnZipFolder As String
Dim FileNameZip As Variant, ShellStr As String
Dim Password As String
'Path of the Zip program
PathZipProgram = "C:\program files\winzip"
If Right(PathZipProgram, 1) <> "\" Then
PathZipProgram = PathZipProgram & "\"
End If
'Check if this is the path where WinZip is installed.
If dir(PathZipProgram & "winzip32.exe") = "" Then
MsgBox "Please find your copy of winzip32.exe and try again"
Exit Function
End If
'Create path and name of the normal folder to unzip the files in
'In this example we use: Application.DefaultFilePath
'Normal if you have not change it this will be your Documents folder
'The name of the folder that the code create in this folder is the Date/Time
NameUnZipFolder = pNameUnzipFolder
'NameUnZipFolder = Application.DefaultFilePath & "\" & Format(Now, "yyyy-mm-dd hh-mm-ss")
'NameUnZipFolder = "C:\Program Files\MCDesign\DULane\Racunovodstvo\Razduzivanje\Izvod\Original"
'You can also use a fixed path like :
'NameUnZipFolder = "C:\Users\Ron\TestFolder\" & Format(Now, "yyyy-mm-dd hh-mm-ss")
'Select the zip file (.zip or .zipx files)
'FileNameZip = Application.GetOpenFilename(filefilter:="Zip Files, *.zip*", _
' MultiSelect:=False, Title:="Select the file that you want to unzip")
FileNameZip = pFileNameZip
'Unzip the files/folders from the zip file in the NameUnZipFolder folder
If FileNameZip = False Then
'do nothing
Else
'There are a few commands/Switches that you can change in the ShellStr
'If you add -j it will not keep the folder stucture, add it if you only want the files
'Use -o if you want to Overwrite existing files without prompting
ShellStr = PathZipProgram & "Winzip32 -min -e -o" _
& " " & Chr(34) & FileNameZip & Chr(34) _
& " " & Chr(34) & NameUnZipFolder & Chr(34)
'Add -s like this -sYourPassWordHere if you want to unzip a file with a password for the files in it
' Password = """topsecret""" 'Do not remove the six quotes
' ShellStr = PathZipProgram & "Winzip32 -min -e -s" & Password _
' & " " & Chr(34) & FileNameZip & Chr(34) _
' & " " & Chr(34) & NameUnZipFolder & Chr(34)
ShellAndWait ShellStr, vbHide
MsgBox "Fajl kreiran uspesno", vbInformation, "Kreiranje Fajla"
'MsgBox "Fajl otpakovan u " & NameUnZipFolder, vbInformation, "Kreiranje Fajla"
End If
End Function