Public Declare Function CreateProcessA Lib "kernel32" (ByVal _
lpApplicationName As Long, ByVal lpCommandLine As String, ByVal _
lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
lpStartupInfo As STARTUPINFO, lpProcessInformation As _
PROCESS_INFORMATION) As Long
Public Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
hHandle As Long, ByVal dwMilliseconds As Long) As Long
Public Const NORMAL_PRIORITY_CLASS = &H20&
Public Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Public Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type
Public Enum enSW
SW_HIDE = 0
SW_NORMAL = 1
SW_MAXIMIZE = 3
SW_MINIMIZE = 6
End Enum
Public Sub ZipFiles()
On Error GoTo errHandler
Dim id As Long
Dim WinZipStr As String
Dim ZipFile As String
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
Dim ReturnValue As Integer
ZipFile = CStr(Year(Date))
ZipFile = ZipFile & CStr(Month(Date))
ZipFile = ZipFile & CStr(Day(Date))
WinZipStr = "C:\Program Files\WinZip\WinZip32 "
WinZipStr = WinZipStr & "-a " & InDir & "\Backup\" & ZipFile & ".zip "
WinZipStr = WinZipStr & InDir & "\*.dat"
start.wShowWindow = enSW.SW_HIDE
ReturnValue = CreateProcessA(0&, WinZipStr, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
' Wait for the shelled application to finish:
Do
ReturnValue = WaitForSingleObject(proc.hProcess, 0)
DoEvents
Loop Until ReturnValue <> 258
Exit Sub
errHandler:
errCnt = errCnt + 1
errMsg = errMsg & "<TD>ZipFiles</TD>"
errMsg = errMsg & "<TD>" & Err.Description & "</TD>"
errMsg = errMsg & "<TD>" & CStr(Date) & " " & CStr(Time) & "</TD></TR><TR>"
WriteError (errMsg)
End Sub