I looked at ww.mrexcel.com/board/threads/zip-series-of-files-with-same-prefix-in-the-same-folder.1154257/
But when I tried to clean up and customize, it does not work for me.
I am trying to zip a group of files within in a directory e,g,, every file that has "*XYZ*.* in directory C:\port\abc
This group is amazing as I always get great responses. Hopefully someone can help me out here
Code is below
THANK YOU! THANK YOU!
Ron
**********************************
Sub Zip_File_Groups()
Dim Sh As Object
Dim FiletoAdd As String
Dim FilePath As String
Dim FilePathSlash As String
Dim ZipFile As String
Dim ZipFileWithPath As String
Dim ShZipFolder As Object
Dim ShFolderItem As Object
'=====================================
' Name FilePath and zip file name
'=====================================
FilePath = "c:\port\ABC"
FilePathSlash = FilePath & "\"
ZipFile = "TEST.ZIP"
ZipFileWithPath = FilePathwithslash + ZipFile
'=================
' Create zip File
'================
Open ZipFileWithPath For Output As #1
Print #1, Chr$(80) & Chr$(75) & Chr$(5) & Chr$(6) & String(18, 0)
Close #1
'=================================
' Loop through the files desired
'=================================
FiletoAdd = Dir(FilePathSlash & "*XYZ*.*")
While FiletoAdd <> vbNullString
Set Sh = CreateObject("Shell.Application")
With Sh
Set ShZipFolder = .Namespace(ZipFileWithPath)
'======================================
'THIS IS THE PROBLEM LINE THAT BLOWS UP and gives me
' "object Variable or with block variable not set"
'========================================
Set ShFolderItem = .Namespace(FilePath).Items().Item(ZipFileWithPath) ' <--- THIS IS THE LINE THAT BLOWS UP
'======================================
ShZipFolder.MoveHere ShFolderItem
DoEvents
End With
FiletoAdd = Dir
Wend
End Sub[/CODE]
But when I tried to clean up and customize, it does not work for me.
I am trying to zip a group of files within in a directory e,g,, every file that has "*XYZ*.* in directory C:\port\abc
This group is amazing as I always get great responses. Hopefully someone can help me out here
Code is below
THANK YOU! THANK YOU!
Ron
**********************************
Sub Zip_File_Groups()
Dim Sh As Object
Dim FiletoAdd As String
Dim FilePath As String
Dim FilePathSlash As String
Dim ZipFile As String
Dim ZipFileWithPath As String
Dim ShZipFolder As Object
Dim ShFolderItem As Object
'=====================================
' Name FilePath and zip file name
'=====================================
FilePath = "c:\port\ABC"
FilePathSlash = FilePath & "\"
ZipFile = "TEST.ZIP"
ZipFileWithPath = FilePathwithslash + ZipFile
'=================
' Create zip File
'================
Open ZipFileWithPath For Output As #1
Print #1, Chr$(80) & Chr$(75) & Chr$(5) & Chr$(6) & String(18, 0)
Close #1
'=================================
' Loop through the files desired
'=================================
FiletoAdd = Dir(FilePathSlash & "*XYZ*.*")
While FiletoAdd <> vbNullString
Set Sh = CreateObject("Shell.Application")
With Sh
Set ShZipFolder = .Namespace(ZipFileWithPath)
'======================================
'THIS IS THE PROBLEM LINE THAT BLOWS UP and gives me
' "object Variable or with block variable not set"
'========================================
Set ShFolderItem = .Namespace(FilePath).Items().Item(ZipFileWithPath) ' <--- THIS IS THE LINE THAT BLOWS UP
'======================================
ShZipFolder.MoveHere ShFolderItem
DoEvents
End With
FiletoAdd = Dir
Wend
End Sub[/CODE]