'********************************************************
'collection fonctions particulières et originales disk Rac 3
'liste des feuilles dans un classeur fermé sur une idée de @laurent950
'auteur :patricktoulon
'version patricktoulon 100% VBA
'********************************************************
Option Explicit
Sub testFX()
Dim ListSheet, FilePath$
'adapter le chemin ici ou injecter un dialog getopenfilename
FilePath$ = "C:\Users\patricktoulon\Desktop\tototo.xlsx"
ListSheet = ListSheetOnClosedFileXML(FilePath)
If UBound(ListSheet) > 0 Then MsgBox Join(ListSheet, vbCrLf)
End Sub
Function ListSheetOnClosedFileXML(lPath As String)
Dim Archiveur, fichierZiP$, fichierxml$, xDoc As Object, noeud, TbL(), A&, FwK
'les chemins de fichiers
fichierZiP = Replace(lPath, ".xlsx", ".zip")
fichierxml = Mid(lPath, 1, InStrRev(lPath, "\")) & "workbook.xml"
'on les supprimes si ils existent
If Dir(fichierZiP) <> "" Then Kill fichierZiP
If Dir(fichierxml) <> "" Then Kill fichierxml
'on copie le fichier Excel(xlsx , xlsm , xlt , xlb) en format zip
FileCopy lPath, fichierZiP
'on ouvre un object shell.application
Set Archiveur = CreateObject("Shell.Application")
'on sort en accès direct le fichier voulu en l'occurrence ici le workbook.xml qui se trouve dans
'fichierZiP & "\xl\workbook.xml"
With Archiveur
Set FwK = .Namespace(fichierZiP & "\xl\").Items.Item("workbook.xml")
If FwK Is Nothing Then 'si le workbook.xml n'est pas trouvé(fichier eventuellement corrompu)
'on supprime zip et xml on en a plus besoin
If Dir(fichierZiP) <> "" Then Kill fichierZiP
If Dir(fichierxml) <> "" Then Kill fichierxml
ListSheetOnClosedFileXML = TbL
End If
'copie du fichier dans la destination
.Namespace(ThisWorkbook.Path).copyhere FwK.Path
End With
' Charger le XML
Set xDoc = CreateObject("MSXML2.DOMDocument.6.0")
xDoc.async = False
xDoc.Load fichierxml
' Ajouter espace de noms pour les feuilles
xDoc.SetProperty "SelectionNamespaces", "xmlns:ss='http://schemas.openxmlformats.org/spreadsheetml/2006/main'"
' Parcourir les feuilles en mode Xpath
For Each noeud In xDoc.SelectNodes("//ss:sheet")
A = A + 1: ReDim Preserve TbL(1 To A)
TbL(A) = noeud.Attributes.getNamedItem("name").Text
Next
'on supprime zip et xml on en a plus besoin
If Dir(fichierZiP) <> "" Then Kill fichierZiP
If Dir(fichierxml) <> "" Then Kill fichierxml
ListSheetOnClosedFileXML = TbL
End Function