Zip un fichier en code vba

Zip un fichier en code vba - VB/VBA/VBS - Programmation

Marsh Posté le 19-01-2011 à 16:22:31    

Bonjour,
 
dans le cadre de mon stage je cherche à améliorer la rapidité sur une de mes tâches et par conséquent j'ai besoin d'un code VBA ! En effet je cherche le moyen d'avoir un msgbox avec dessus "Zip" qui comme son nom l'indique permet de zipper un fichier ! Je ne sais pas si une tel macro existe. De plus, je passe obligatoirement par winzip !
 
Je vous remercie par avance pour toute aide!

Reply

Marsh Posté le 19-01-2011 à 16:22:31   

Reply

Marsh Posté le 19-01-2011 à 17:38:18    

Salut, voir sur http://www.rondebruin.nl/tips.htm le paragraphe "Zip (compress) ActiveWorkbook, Folder, File or Files with VBA code"


Option Explicit
 
Sub ZipFichier()
Dim oShell As Object
Dim FSO As Object
Dim i As Long
Dim sFichier As String, sBin As String
Dim sZip As Variant, vHexa As Variant
 
    sFichier = ThisWorkbook.Path & "\" & "Essai.xls"
    sZip = ThisWorkbook.Path & "\" & "Essai.zip"
 
    Set FSO = CreateObject("Scripting.FileSystemObject" )
    vHexa = Array(80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
 
    For i = 0 To UBound(vHexa)
        sBin = sBin & Chr(vHexa(i))
    Next i
 
    With FSO.CreateTextFile(sZip, True)
        .Write sBin
        .Close
    End With
 
    Set oShell = CreateObject("Shell.Application" )
    oShell.Namespace(sZip).CopyHere (sFichier)
     
    Set oShell = Nothing
    Set FSO = Nothing
End Sub


Message édité par kiki29 le 20-01-2011 à 07:11:29
Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed