I didn't realize you couldn't answer to an individual. Your explanation makes sense and I will be more careful in the future.
Thanks for the heads up.
Thanks for the heads up.
Dim mzipfile As khZip Dim StrSavePath, StrZipDir As String Set mzipfile = New khZip With mzipfile 'zip chosen files .ZipFilePath = strfoldername + "\" & MyZipFileName .ZipFiles.Add strfoldername + "\extractcat.csv" .ZipFiles.Add strfoldername + "\extractdata.csv" .ZipFiles.Add strfoldername + "\extractparm.csv" .Zip End With
'--------------------------------------------------------------------------------------- ' Module : khZip ' DateTime : 5/18/2007 14:02 ' Author : Ken Jensen ' Purpose : Automate the Windows XP zip functionality '--------------------------------------------------------------------------------------- Option Compare Database Option Explicit Private Const ERRSOURCE As String = "Zip" Private mobjZipFile As khZipFiles Private mstrZipFilePath As String Private mstrUnzipFolderPath As String Private mstrZipFolderPath As String Private mstrZipFilePath_Temp As String Public Property Get ZipFilePath() As String ZipFilePath = mstrZipFilePath End Property Public Property Let ZipFilePath(strZipFilePathIn As String) mstrZipFilePath = strZipFilePathIn End Property Private Sub Class_Initialize() On Error GoTo Err_Class_Initialize Set mobjZipFile = New khZipFile Exit_Class_Initialize: Exit Sub Err_Class_Initialize: Err.Raise Err.Number, Err.Source & " - ActlZip - Class_Initialize " & Erl, Err.Description Resume Exit_Class_Initialize End Sub Public Sub Zip() On Error GoTo Err_Zip Dim objShell As Object Dim objFolder As Object Dim lngCnt As Long If IsNull(Me.ZipFilePath) Then MsgBox "You must include a path for the zip file", vbOKOnly + vbExclamation Else If mobjZipFile.Count < 1 Then MsgBox "You must include at least one file to be zipped", vbOKOnly + vbExclamation Else NewZip Me.ZipFilePath Set objShell = CreateObject("Shell.Application") Set objFolder = objShell.NameSpace(Me.ZipFilePath) For lngCnt = 1 To mobjZipFile.Count objFolder.CopyHere mobjZipFile.ZipFileString(lngCnt) Next lngCnt 'Keep script waiting until Compressing is done On Error Resume Next Do Until objFolder.Items.Count = lngCnt - 1 DoEvents Loop On Error GoTo Err_Zip End If End If Exit_Zip: Set objShell = Nothing Set objFolder = Nothing Exit Sub Err_Zip: Err.Raise Err.Number, Err.Source & " - khZip - Zip " & Erl, Err.Description Resume Exit_Zip End Sub Public Sub UnZipAll() On Error GoTo Err_UnZipAll Dim objShell As Object Set objShell = CreateObject("Shell.Application") objShell.NameSpace(Me.UnzipFolderPath).CopyHere objShell.NameSpace(Me.ZipFilePath).Items Exit_UnZipAll: Set objShell = Nothing Exit Sub Err_UnZipAll: Err.Raise Err.Number, Err.Source & " - khZip - UnZipAll " & Erl, Err.Description Resume Exit_UnZipAll End Sub Public Sub ZipAll() On Error GoTo Err_ZipAll Dim objShell As Object Dim objFolder As Object Dim objFolder2 As Object Dim tmpFolder As String If IsNull(Me.ZipFilePath) Then MsgBox "You must include a path for the zip file", vbOKOnly + vbExclamation Else 'create temp file then move after zipping 'issue when try to zip all files in folder if zip file is placed in same folder tmpFolder = "C:\Temp" & "\" If Dir(tmpFolder) = "" Then On Error Resume Next MkDir tmpFolder End If On Error GoTo Err_ZipAll Me.ZipFilePath_Temp = "C:\Temp\" & Right$(Me.ZipFilePath, Len(Me.ZipFilePath) - InStrRev(Me.ZipFilePath, "\")) NewZip Me.ZipFilePath_Temp If Right$(Me.ZipFolderPath, 1) <> "\" Then Me.ZipFolderPath = Me.ZipFolderPath & "\" End If Set objShell = CreateObject("Shell.Application") Set objFolder = objShell.NameSpace(Me.ZipFilePath_Temp) Set objFolder2 = objShell.NameSpace(Me.ZipFolderPath) objFolder.CopyHere objFolder2.Items 'Keep script waiting until Compressing is done On Error Resume Next Do Until objFolder.Items.Count = objFolder2.Items.Count DoEvents Loop On Error GoTo Err_ZipAll If Len(Dir(Me.ZipFilePath)) > 0 Then Kill Me.ZipFilePath End If Name Me.ZipFilePath_Temp As Me.ZipFilePath End If Exit_ZipAll: Set objShell = Nothing Set objFolder = Nothing Set objFolder2 = Nothing Exit Sub Err_ZipAll: Err.Raise Err.Number, Err.Source & " - khZip - ZipAll " & Erl, Err.Description Resume Exit_ZipAll End Sub Public Property Get ZipFiles() As khZipFiles Set ZipFiles = mobjZipFile End Property Private Sub Class_Terminate() On Error Resume Next Set mobjZipFile = Nothing End Sub Public Property Get UnzipFolderPath() As String UnzipFolderPath = mstrUnzipFolderPath End Property Public Property Let UnzipFolderPath(strUnzipFolderPathIn As String) mstrUnzipFolderPath = strUnzipFolderPathIn End Property Public Property Get ZipFolderPath() As String ZipFolderPath = mstrZipFolderPath End Property Public Property Let ZipFolderPath(strZipFolderPathIn As String) mstrZipFolderPath = strZipFolderPathIn End Property Friend Property Get ZipFilePath_Temp() As String ZipFilePath_Temp = mstrZipFilePath_Temp End Property Friend Property Let ZipFilePath_Temp(strZipFilePath_TempIn As String) mstrZipFilePath_Temp = strZipFilePath_TempIn End Property
'--------------------------------------------------------------------------------------- ' Module : khZipFile ' DateTime : 5/18/2007 14:02 ' Author : Ken Jensen ' Purpose : Automate the Windows XP zip functionality '--------------------------------------------------------------------------------------- Option Compare Database Option Explicit Private Const ERRSOURCE As String = "ZipFile" Private mstrName As String Public Property Get Name() As String Name = mstrName End Property Public Property Let Name(strNameIn As String) mstrName = strNameIn End Property
'--------------------------------------------------------------------------------------- ' Module : khZipFiles ' DateTime : 5/18/2007 14:02 ' Author : Ken Jensen ' Purpose : Automate the Windows XP zip functionality '--------------------------------------------------------------------------------------- Option Compare Database Option Explicit Private Const ERRSOURCE As String = "ZipFile" Private mcln As Collection Public Function Add(strName) As khZipFile Dim r As khZipFile On Error GoTo Err_Add Set r = New khZipFile r.Name = strName mcln.Add r, strName Set Add = r Exit_Add: Set r = Nothing Exit Function Err_Add: Err.Raise Err.Number, Err.Source & "-" & ERRSOURCE, Err.Description Resume Exit_Add End Function Private Sub Class_Initialize() Set mcln = New Collection End Sub Public Property Get Count() Count = mcln.Count End Property Public Function Remove(strName As String) mcln.Remove strName End Function Public Property Get Item(strName) As khZipFile Set Item = mcln(strName) End Property Private Sub Class_Terminate() Set mcln = Nothing End Sub Friend Function ZipFileString(lngCount As Long) As String ZipFileString = mcln(lngCount).Name End Function
Private Sub Class_Initialize() 'Nothing required in here as it's just a dummy. End Sub
Comment