Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

zip access vba

zip access vba

zip access vba


I want to zip some files in my folder.
i used this code:

'Compacta e Zip
Private Declare Sub Sleep Lib "kernel32" ( _
ByVal dwMilliseconds As Long _

Sub compactar_BD01()
Application.SetOption "Auto compact", True

'nome do zip / nome do ficheiro origem

Zip "G:\OrcControlo\SCC\Processo\Backups\00Custos_tabelas_gerais.zip", "G:\OrcControlo\SCC\Processo\00Custos_tabelas_gerais.mdb"
Zip "G:\OrcControlo\SCC\Processo\Backups\01Custos_SAN.zip", "G:\OrcControlo\SCC\Processo\01Custos_SAN.accdb"
Zip "G:\OrcControlo\SCC\Processo\Backups\03Custos_FH2.zip", "G:\OrcControlo\SCC\Processo\03Custos_FH2.mdb"
Zip "G:\OrcControlo\SCC\Processo\Backups\04Custos_FHC.zip", "G:\OrcControlo\SCC\Processo\04Custos_FHC.mdb"
Zip "G:\OrcControlo\SCC\Processo\Backups\05Custos_FHD.zip", "G:\OrcControlo\SCC\Processo\05Custos_FHD.mdb"
Zip "G:\OrcControlo\SCC\Processo\Backups\06Custos_FHP.zip", "G:\OrcControlo\SCC\Processo\06Custos_FHP.mdb"

End Sub

Public Sub Zip( _
ZipFile As String, _
InputFile As String _
On Error GoTo ErrHandler
Dim FSO As Object 'Scripting.FileSystemObject
Dim oApp As Object 'Shell32.Shell
Dim oFld As Object 'Shell32.Folder
Dim oShl As Object 'WScript.Shell
Dim i As Long
Dim l As Long

Set FSO = CreateObject("Scripting.FileSystemObject")
If Not FSO.FileExists(ZipFile) Then
'Create empty ZIP file
FSO.CreateTextFile(ZipFile, True).Write _
"PK" & Chr(5) & Chr(6) & String(18, vbNullChar)
End If

Set oApp = CreateObject("Shell.Application")
Set oFld = oApp.Namespace(CVar(ZipFile))
i = oFld.items.Count
oFld.CopyHere (InputFile)

Set oShl = CreateObject("WScript.Shell")

'Search for a Compressing dialog
Do While oShl.AppActivate("Compressing...") = False
If oFld.items.Count > i Then
'There's a file in the zip file now, but
'compressing may not be done just yet
Exit Do
End If
If l > 30 Then
'3 seconds has elapsed and no Compressing dialog
'The zip may have completed too quickly so exiting
Exit Do
End If
Sleep 100
l = l + 1

' Wait for compression to complete before exiting
Do While oShl.AppActivate("Compressing...") = True
Sleep 100

On Error Resume Next
Set FSO = Nothing
Set oFld = Nothing
Set oApp = Nothing
Set oShl = Nothing
Exit Sub
Select Case Err.Number
Case Else
MsgBox "Error " & Err.Number & _
": " & Err.Description, _
vbCritical, "Unexpected error"
End Select
Resume ExitProc
End Sub

i don't want zip file by file. i want to zip all the files at the same time. i want to have a zip and when i run the zip i should be able to see the 6 files that i want..

can you help ?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close