PDA

View Full Version : Solved: WinZipping a Folder Errors



SherryO
02-02-2006, 06:54 AM
Hi,
I am trying to run the routine below (functions listed below that) and it doesn't zip anything, but it gives the message that there is a zip file ready in C:\Program Files\Microsoft Office\Office10, but there is no file and that's not the directory I want it in. I'm stumped. Can someone please correct me?
Thanks!!!

Sub ZipFolder()
Dim PathWinZip As String, FileNameZip As String, FolderName As String
Dim ShellStr As String, strDate As String, pPath As String
PathWinZip = "C:\program files\winzip\"

'****This will check if this is the path where WinZip is installed.
If Dir(PathWinZip & "winzip32.exe") = "" Then
MsgBox "WinZip is not installed. Please install it and try again."
Exit Sub
End If

'****Build the path and name for the zip file
pPath = "C:\WithoutCost\"
FileNameZip = "Test.zip"
FolderName = "C:\WithoutCost\"

'****Zip the folder, -r is Include subfolders, -p is folder information
ShellStr = PathWinZip & "Winzip32 -min -a -r -p" & " " & Chr(34) & _
FolderName & Chr(34) & " " & Chr(34) & FileNameZip & Chr(34)
ShellAndWait ShellStr, vbHide
MsgBox "The zipfile is ready in: " & Path & FileNameZip
End Sub


Functions:
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 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

Killian
02-06-2006, 02:43 AM
Hi Sherry,

Your message is giving the wrong pathMsgBox "The zipfile is ready in: " & Path & FileNameZip
'should be
MsgBox "The zipfile is ready in: " & FolderName & FileNameZip"Path" giving the application path.

SherryO
02-06-2006, 09:06 AM
Thank you!!