Autres je n'arrive pas a extraire les éléments d'une archive

patricktoulon

XLDnaute Barbatruc
bonjour a tous
je n'arrive pas a extraire les éléments d'une archive vers un dossiers

VB:
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
puré je m'arrache les cheveux
 
Solution
Bonjour Patrick,
je suis pas certain d'avoir compris!

Code de kiki29!
Code:
 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...

patricktoulon

XLDnaute Barbatruc
re
non j'ai toujours la même erreur (91) " variable indéfinie "
demo7.gif
 

laurent950

XLDnaute Accro
Bonjour Patrick,

Si cela peu t'aider Patrick, les références qui m'on servis


Le code :

VB:
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
 
Dernière édition:

patricktoulon

XLDnaute Barbatruc
ok laurent bonjour
ça voudrais dire fichier.path est différent que le chemin écrit en dur
c'est quand même étonnant que sur mon costumUI creator ça marche
maintenant j'en suis a la dernière etape
j'arrive a renvoyer un dossier dynamique "customUI avec tout ces composants et le nouveau _rels mais le dernier contentType.xml ne veux pas passer

je garde ton idée que je vais tester mais lister c'est pas le but
le but est d'extraire et d'injecter des fichiers ou dossiers
 

dysorthographie

XLDnaute Accro
Bonjour Patrick,
je suis pas certain d'avoir compris!

Code de kiki29!
Code:
 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
 

job75

XLDnaute Barbatruc
Bonjour à tous,

Chez moi ceci va bien à condition de ne pas déclarer les variables :
VB:
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
A+
 

patricktoulon

XLDnaute Barbatruc
🤣 cc' Robert

et oui bonjour job75 j'ai vu ça aussi ou en variant
étonnant cet object 🤔
après lister ca va ca passe
mais le namespace(destination ) movehere namespaces(source) et vice et versa marche pour les 1,2 premier et le 3eme pouf pas d'erreur mais rien
 

patricktoulon

XLDnaute Barbatruc
re
ma fois je sais pas j'ai cherché voir si d'autres ont eu ce problème ,mais je n'ai trouvé de probant
ça m'ennuie j'ai juste ce dernier fichier a mettre et c'est bon j'ai plus l'erreur de fichier a réparer quand j'ouvre le fichier après
c'est peut être les caractères particulier"[contentTipe].xml"
je vais essayer sans voir si c'est ça
 

patricktoulon

XLDnaute Barbatruc
j'ai testé c'est pas les caractères particuliers
bon je vous ait fait un hersât du projet avec la fonction de compilation
j'ai remplacé mon userform creator par des code xml dans les cellules pour les tests ça ira très bien
lancer la sub test

la fonction est sensée
  1. créer un classeur 'ok
  2. le zipper 'ok
  3. extraire le dossier _rels d'origine 'ok(je le jette)
  4. créer un dossier dezip
  5. extraire le [contenttType].xml dans dezip 'ok
  6. créer dans dezip un dossier rel avec le new ".rels" a l’intérieur 'ok
  7. créer dans dezip un dossier customUI avec les 2 customUI xml (2007 et les supérieurs 'ok
  8. créer un dossier customUI_rel dans le dossier customUI 'ok
  9. créer un customUI_rel pour les relationship des image 'ok
  10. envoyer le dossier image du projet dans le dossier customUI de dezip 'ok
  11. modifier le [contenttType].xml ajouter les extension d'images utilisées pour les icons dans dezip 'ok
  12. réinjecter le new _rels 'ok
  13. réinjecter tout le customui 'ok
  14. réinjecter le [contenttType].xml'C EST ICI QUE CA LE FAIT PAS pas ok et pas de msg d'erreur
  15. et enfin rechanger l'extension "zip" pour"xlsm" sur le sample.zip 'ok mais bloqué pour les tests

voila maintenant nous avons le même code

si vous prenez le contentTypexml et que vous l'ajoutez manuellement
dans l'archive et changez l'extension le classeur fonctionne avec le new ribbon
 

Pièces jointes

  • demo.zip
    75 KB · Affichages: 9
Dernière édition:

Statistiques des forums

Discussions
312 180
Messages
2 085 995
Membres
103 082
dernier inscrit
adri77