Sub test()
Dim sh, sampleC$, sampleZip$, i , n
sampleC = ThisWorkbook.Path & "\toto.xlsm"
sampleZip = ThisWorkbook.Path & "\toto.zip"
decompil = ThisWorkbook.Path & "\decompilation"
If Dir(sampleZip) <> "" Then Kill sampleZip
With Workbooks.Add: .SaveAs Filename:=sampleC, FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False: .Close: End With
Application.ScreenUpdating = True
Do While Dir(sampleC) = "": DoEvents: Loop 'attente creation
Name sampleC As sampleZip 'conversion en archive ZIP
Do While Dir(sampleZip) = "": DoEvents: Loop
Set sh = CreateObject("shell.application")
'sh.Namespace(decompil).movehere sh.Namespace(sampleZip).items.Item("_rels")'fonctionne pas
Set n = sh.Namespace(sampleZip)
For Each i In n.items ' ici ça plante
Debug.Print i.Path
Next
End Sub
Option Explicit
Sub Unzip()
Dim FSO As Object
Dim oApp As Object
Dim DossierZip As Variant
Dim DossierDezip As Variant
DossierZip = ThisWorkbook.Path & "\toto.zip"
DossierDezip = ThisWorkbook.Path & "\Data"
Set FSO = CreateObject("Scripting.FileSystemObject")
If FSO.FolderExists(DossierDezip) Then
FSO.DeleteFile DossierDezip & "\*.*", True
FSO.DeleteFolder DossierDezip & "\*.*", True
End If
Set FSO = Nothing
If CreationDossier(DossierDezip) Then
Set oApp = CreateObject("Shell.Application")
oApp.Namespace(DossierDezip).CopyHere oApp.Namespace(DossierZip).items
Set oApp = Nothing...
sh.Namespace(ThisWorkbook.Path).CopyHere sh.Namespace(sampleZip).items
Sub test()
Dim sh, sampleC$, sampleZip$, i, n
sampleC = ThisWorkbook.Path & "\toto.xlsm"
répertoire_zip = ThisWorkbook.Path
sampleZip = ThisWorkbook.Path & "\toto.zip"
decompil = ThisWorkbook.Path & "\decompilation"
If Dir(sampleZip) <> "" Then Kill sampleZip
With Workbooks.Add: .SaveAs Filename:=sampleC, FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False: .Close: End With
Application.ScreenUpdating = True
Do While Dir(sampleC) = "": DoEvents: Loop 'attente creation
Name sampleC As sampleZip 'conversion en archive ZIP
Do While Dir(sampleZip) = "": DoEvents: Loop
'
Set sh = CreateObject("shell.application")
Set FSO = CreateObject("Scripting.FileSystemObject")
Set n = FSO.GetFolder(répertoire_zip)
'
For Each fichier In n.Files
If FSO.GetExtensionName(fichier.Path) = "zip" Then
Debug.Print fichier.Path
'sh.Namespace(répertoire_zip).CopyHere sh.Namespace(fichier.Path).items
'sh.Namespace(decompil).CopyHere sh.Namespace(fichier.Path).items
' Boucle sur les Item
For Each i In sh.Namespace(fichier.Path).items ' ici ça Fonctionne
Debug.Print i.Path
sh.Namespace(decompil).CopyHere i.Path ' Recopie dans le Répertoire decompil
Next
End If
Next
End Sub
Option Explicit
Sub Unzip()
Dim FSO As Object
Dim oApp As Object
Dim DossierZip As Variant
Dim DossierDezip As Variant
DossierZip = ThisWorkbook.Path & "\toto.zip"
DossierDezip = ThisWorkbook.Path & "\Data"
Set FSO = CreateObject("Scripting.FileSystemObject")
If FSO.FolderExists(DossierDezip) Then
FSO.DeleteFile DossierDezip & "\*.*", True
FSO.DeleteFolder DossierDezip & "\*.*", True
End If
Set FSO = Nothing
If CreationDossier(DossierDezip) Then
Set oApp = CreateObject("Shell.Application")
oApp.Namespace(DossierDezip).CopyHere oApp.Namespace(DossierZip).items
Set oApp = Nothing
Application.StatusBar = "Les fichiers Dézippés se trouvent dans : " & DossierDezip
End If
End Sub
Function CreationDossier(ByVal sChemin As String) As Boolean
Dim i As Integer, sTmp As String, Ar() As String
If InStr(sChemin, ":") = 0 Then
Ar = Split(CurDir & "\" & sChemin, "\")
Else
Ar = Split(sChemin, "\")
End If
sTmp = Ar(0)
ChDrive sTmp
For i = LBound(Ar) + 1 To UBound(Ar)
If Ar(i) <> "" Then
sTmp = sTmp & "\" & Ar(i)
On Error Resume Next
MkDir sTmp
On Error GoTo 0
End If
Next i
If Dir(sChemin, vbDirectory) = vbNullString Then
CreationDossier = False
Else
CreationDossier = True
End If
End Function
Sub a()
sampleC = ThisWorkbook.Path & "\toto.xlsm"
sampleZip = ThisWorkbook.Path & "\toto.zip"
If Dir(sampleC) <> "" Then Kill sampleC 'RAZ
If Dir(sampleZip) <> "" Then Kill sampleZip 'RAZ
With Workbooks.Add: .SaveAs sampleC, xlOpenXMLWorkbookMacroEnabled: .Close: End With
Do While Dir(sampleZip) = "": Name sampleC As sampleZip: DoEvents: Loop
Set sh = CreateObject("shell.application")
For Each i In sh.Namespace(sampleZip).items
Debug.Print i.Path
Next
End Sub
Ces déclarations sont acceptées :à condition de ne pas déclarer les variables :
Dim sampleC$, sampleZip, sh As Object, i As Object