Can someone please help me figure out why I'm stuck in an infinite loop when adding a file to the zip file? The first file it is attempting to zip is only 16kb and I've let it run for 30minutes and nothing appears to be going into the zip file.
Any ideas?
Any ideas?
Code:
Sub Archive_files()
Application.DisplayAlerts = False
Dim NetworkLoc As String
Dim CurDate As Date
Dim SOMonth As Date
Dim LookupFile As String, x
Dim CopyFile
Dim srcFile As String
Dim oApp As Object
Dim I As Integer
Dim FileNameZip As String
Dim ArchiveFolder As String
Dim ZipFiles As String
NetworkLoc = <<insert Network location here>>
CurDate = Workbooks("Testing.xlsb").Sheets("Sheet1").Range("B2").Value
SOMonth = DateSerial(Year(CurDate), Month(CurDate), 1) - 1
ArchiveFolder = NetworkLoc & "Archive\"
FileNameZip = ArchiveFolder & Format(SOMonth, "mm-yyyy") & ".zip"
CopyFile = Array(NetworkLoc & "*" & Format(SOMonth, "Mmmm") & "*")
For Each x In CopyFile
LookupFile = Dir(NetworkLoc & x)
Do While LookupFile <> ""
srcFile = NetworkLoc & LookupFile
FileCopy srcFile, ArchiveFolder & LookupFile
' Kill srcFile
LookupFile = Dir
Loop
Next
If Len(Dir(FileNameZip)) > 0 Then Kill FileNameZip
Open FileNameZip For Output As #1
Print #1, Chr$(80) & Chr$(75) & Chr$(5) & Chr$(6) & String(18, 0)
Close #1
ZipFiles = Dir(ArchiveFolder & "*" & Format(SOMonth, "Mmmm") & "*")
Set oApp = CreateObject("Shell.Application")
I = 0
Do While ZipFiles <> ""
oApp.Namespace(FileNameZip).CopyHere oApp.Namespace(ArchiveFolder & ZipFiles).Items
I = I + 1
Do Until oApp.Namespace(FileNameZip).Items.Count = I
Application.Wait (Now + TimeValue("0:00:01"))
Loop
ZipFiles = Dir
Loop
End Sub