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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Zipping / Unzipping files using VB/VBA and WinZip?

Status
Not open for further replies.

VBAguy22

IS-IT--Management
Aug 5, 2003
180
CA
Hello,
Is is possible to Zip/Unzip files using VB with WinZip?
Say I have a list of 10 files in C:\Temp\ and I need to zip them giving them a name "TempFiles.zip" and erase the 10 files.
Then I need to unzip C:\Temp\TempFiles.zip into C:\Temp\ directory.
All the above to be done with the default Zip options and preferences (I do not need to change any options programatically)

thanx
 
I guess you could use ShellAndWait, giving the file names as arguments to the program your calling, eg. UZip.exe myfile or whatever....
Lifted this from vb-helper.com: (hope it helps)
You obviously can't just use the ShellExecute call as you want to do something with the result of the program you are calling, ie. the zipped files -- this is were I think shell&wait would come in useful. Not actually tries it myself so let me know how you get on.

Private Sub ShellAndWait(ByVal program_name As String, _
ByVal window_style As VbAppWinStyle)
Dim process_id As Long
Dim process_handle As Long

' Start the program.
On Error GoTo ShellError
process_id = Shell(program_name, window_style)
On Error GoTo 0

' Hide.
Me.Visible = False
DoEvents

' Wait for the program to finish.
' Get the process handle.
process_handle = OpenProcess(SYNCHRONIZE, 0, process_id)
If process_handle <> 0 Then
WaitForSingleObject process_handle, INFINITE
CloseHandle process_handle
End If

' Reappear.
Me.Visible = True
Exit Sub

ShellError:
MsgBox &quot;Error starting task &quot; & _
txtProgram.Text & vbCrLf & _
Err.Description, vbOKOnly Or vbExclamation, _
&quot;Error&quot;
End Sub
 

I belive winzip has a command line utility that you can download. I have communicated with them in the past and they do not have an automation interface with their product (activex). Their work is based upon the info zip dlls.

Good Luck

 
cjac: My VBA doesnt recognize OpenProcess method. Weird.
 

You need the API declarations for that code to work. If you search for shell and wait you will find the whole code.

Good Luck

 

VBAguy22, did you search this site for shell and wait? Did you get your problems solved?

Good Luck

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top