AT_Zip.bas 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. ' Add reference to:
  2. ' 1. Microsoft Scripting Runtime
  3. ' 2. Microsoft Shell Controls and Automation
  4. ' From Tools > Reference
  5. Option Explicit
  6. Option Base 0
  7. Private Declare Sub Sleep Lib "kernel32" (ByVal dwMiliseconds As Long)
  8. Public Sub zipfile(zipPath As String, filePath As String)
  9. createzip zipPath
  10. addfile zipPath, filePath
  11. End Sub
  12. Public Sub zipfolder(zipPath As String, folderpath As String)
  13. Dim file As Variant
  14. createzip zipPath
  15. For Each file In CreateObject("Scripting.FileSystemObject").GetFolder(folderpath).Files
  16. addfile zipPath, CStr(file)
  17. Next file
  18. End Sub
  19. Private Sub addfile(zipPath As String, filePath As String)
  20. Dim sh As Shell32.Shell, fdr As Shell32.Folder, cntItems As Integer 'cnt = Count
  21. Set sh = CreateObject("Shell.Application")
  22. Set fdr = sh.NameSpace(zipPath)
  23. cntItems = fdr.Items.Count
  24. fdr.CopyHere filePath, 4 + 16 + 1024
  25. Do
  26. Sleep 1000
  27. Loop Until cntItems < fdr.Items.Count
  28. Set fdr = Nothing
  29. Set sh = Nothing
  30. End Sub
  31. Private Sub createzip(zipPath As String)
  32. Dim fso As Scripting.FileSystemObject
  33. Set fso = CreateObject("Scripting.FileSystemObject")
  34. If fso.FileExists(zipPath) Then
  35. fso.DeleteFile zipPath
  36. End If
  37. fso.CreateTextFile(zipPath).Write "PK" & Chr(5) & Chr(6) & String(18, Chr(0))
  38. Set fso = Nothing
  39. End Sub