Results 1 to 3 of 3

Thread: Solved: WinZipping a Folder Errors

  1. #1

    Solved: WinZipping a Folder Errors

    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?

    [VBA]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 = ""
    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

    [VBA]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 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)
    'populate Exitcode variable
    GetExitCodeProcess hProcess, ExitCode
    Loop While ExitCode = STILL_ACTIVE
    End Sub[/VBA]
    Last edited by Killian; 02-06-2006 at 02:45 AM. Reason: Fixed VBA tags

  2. #2
    VBAX Master Killian's Avatar
    Nov 2004
    Hi Sherry,

    Your message is giving the wrong path[VBA]MsgBox "The zipfile is ready in: " & Path & FileNameZip
    'should be
    MsgBox "The zipfile is ready in: " & FolderName & FileNameZip[/VBA]"Path" giving the application path.
    K :-)

  3. #3
    Thank you!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts