Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Winzip (wzzip.exe) via access 1

Status
Not open for further replies.

SkyHigh

Technical User
May 30, 2002
309
CA
Hi Folks

I am using the following code to zip up a selected folder but it doesn't work and I get the msg saying the file doesn't exist but it does exist, please help - thanks

---
Code:
---



    Set objFSO = CreateObject("Scripting.FileSystemObject")

    sTempZipFolder = "c:\Temp"
    sFileName = Chr$(34) & Me.txtFileToZipAttach.Value & Chr$(34)
    sZipName = Chr$(34) & sTempZipFolder & "\Reports.zip" & Chr$(34)
    
    If objFSO.FileExists(sFileName) Then
       MsgBox sFileName & " exists"    
        Set objShell = CreateObject("WScript.Shell")
        Set objCmd = objShell.Exec("C:\Program Files\WinZip\wzzip.exe -ybc" & " " & sZipName & " " & sFileName, 1, True)
        Set objCmd = Nothing
        Set objShell = Nothing
        
    Else
        MsgBox sFileName & " doesn't exist"
        
    End If

---[Code]---
 
This
sFileName = Chr$(34) & Me.txtFileToZipAttach.Value & Chr$(34)

gives you

"somefile"

While somefile may exist, "somefile" does not. Remove the quotation marks.
 
Even after removing the quotes I have the same problem :

Set objFSO = CreateObject("Scripting.FileSystemObject")

sTempZipFolder = "c:\Temp"
sFileName = Me.txtFileToZipAttach.Value
sZipName = sTempZipFolder & "\Reports.zip"

If objFSO.FileExists(sFileName) Then
MsgBox sFileName & " exists"
Set objShell = CreateObject("WScript.Shell")
Set objCmd = objShell.Exec("C:\Program Files\WinZip\wzzip.exe -ybc" & " " & sZipName & " " & sFileName, 1, True)
Set objCmd = Nothing
Set objShell = Nothing

Else
MsgBox sFileName & " doesn't exist"

End If
 
I am actually trying to zip up a folder !
 
The problem was with the winzip switch I did some research found the right switch and it works.

However, Here's another problem, what I want to do is to zip up a selected folder and send it by email and what happening is that ithe zipping process takes a while which code doesn't wait for - how can I make it to wait for the zip process to finish before it gets to the next step of sending email, here's the code

---
Code:
---

        sZipName = "C:\Temp\Reports.zip"
        sFileName = Trim(Me.txtFileToZipAttach.Value)
        vEmailTo = Me.txtTo.Value
        vEmailCc = Me.txtCc.Value
        vEmailBcc = Me.txtBcc.Value
        vEmailSubject = Me.txtSubject.Value
        vEmailMsg = Me.txtMsg.Value
        strOrgAttPath = sZipName


         Shell "C:\Program Files\WinZip\wzzip.exe -pr " & Chr(34) & sZipName & Chr(34) & " " & Chr(34) & sFileName & Chr(34)


                    Set objOutlook = CreateObject("Outlook.application")
                    Set objEmail = objOutlook.CreateItem(olMailItem)
                            
                        With objEmail
                            .To = vEmailTo
                            .CC = vEmailCc
                            .BCC = vEmailBcc
                            .Subject = "ORG - " & vEmailSubject
                            .Body = vEmailMsg & vbCrLf & vbCrLf & vbCrLf & "This email is generated automatically by OLE Automation in Reporting Tool"
                            .Attachments.Add (strOrgAttPath)
                            .Send
                        End With
                        
                    Set objOutlook = Nothing
                    Set objEmail = Nothing
                    Kill sZipName

---[Code]---
 
Replace this:
Shell "C:\Program Files\WinZip\wzzip.exe -pr " & Chr(34) & sZipName & Chr(34) & " " & Chr(34) & sFileName & Chr(34)
By this:
Set sh = CreateObject("WScript.Shell")
rc = sh.Run("C:\Program Files\WinZip\wzzip.exe -pr " & Chr(34) & sZipName & Chr(34) & " " & Chr(34) & sFileName & Chr(34), 1, True)

rc will contain the return code of wzzip.exe

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top