Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

zip access vba

Status
Not open for further replies.

JoanaSantos

Programmer
Feb 24, 2015
33
EU
Hi,

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
DoEvents
Sleep 100
l = l + 1
Loop

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

ExitProc:
On Error Resume Next
Set FSO = Nothing
Set oFld = Nothing
Set oApp = Nothing
Set oShl = Nothing
Exit Sub
ErrHandler:
Select Case Err.Number
Case Else
MsgBox "Error " & Err.Number & _
": " & Err.Description, _
vbCritical, "Unexpected error"
End Select
Resume ExitProc
Resume
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 ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top