Private Declare PtrSafe Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare PtrSafe 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 Sub 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 Sub
Sub B_UnZip_Zip_File_Fixed()
Dim PathZipProgram As String, NameUnZipFolder As String
Dim FileNameZip As Variant, ShellStr As String
'Path of the Zip program
PathZipProgram = "c:\program files\7-Zip"
If Right(PathZipProgram, 1) <> "\" Then
PathZipProgram = PathZipProgram & "\"
End If
'Check if this is the path where 7z is installed.
If dir(PathZipProgram & "7z.exe") = "" Then
MsgBox "Please find your copy of 7z.exe and try again"
Exit Sub
End If
'You can also use a fixed path like
NameUnZipFolder = "C:\Users\Bala\Documents\Test"
'Name of the zip file that you want to unzip (.zip or .7z files)
FileNameZip = "C:\Users\Bala\Documents\Test\bala.vignesh.zip"
If dir(NameUnZipFolder & "bala.vignesh.zip") = "" Then
MsgBox "bala.zip file not available please check"
Exit Sub
End If
ShellStr = PathZipProgram & "7z.exe e -aou -r" _
& " " & Chr(34) & FileNameZip & Chr(34) _
& " -o" & Chr(34) & NameUnZipFolder & Chr(34) & " " & "*.*"
ShellAndWait ShellStr, vbHide
MsgBox "Look in " & NameUnZipFolder & " for extracted files"
End Sub