'****************************************************************************************************
'    __    _  _  _   _   _       _   _ _______  ___     ___     _  ___     _       ____ _______ ____
'   // \\ // // //  //  /\\     //  //   //    //  \\  // ||   // // ||   /\\     //      //   //
'  //__// \\// //  //  //__\   //  //   //    //   // //  ||  // //  ||  //__\   //      //   //__
' //  \\   // //  //  //   \\ //  //   //    //   // //   // // //   // //   \\ //      //   //
'//   //  // //__//  //    ////__//   //     \\__// //___// // //___// //    ////___   //   //___
'
'responsable et concepteur [operating System]du module "Modul_CreateXLfileMac"
'
'****************************************************************************************************
'Public modecreation
Sub createmacfichXL()
    Dim VBComp, cbBack, Codxml
    Dim SampleC$, SampleZIP, ProjetUI, Oapp, x&, i&, f
    Dim Cod$, Q14, elem, FolderCustomUI
    'chemin des dossiers et fichier
    SampleC = ThisWorkbook.Path & Application.PathSeparator & "Sample.xlsm"
    SampleZIP = ThisWorkbook.Path & Application.PathSeparator & "Sample.Zip"
    ProjetUI = ThisWorkbook.Path & Application.PathSeparator & "ProjetUI" 'dossier de dezipage temporaire
    FolderCustomUI = ThisWorkbook.Path & Application.PathSeparator & "customUI"
    If Dir(FolderCustomUI, vbDirectory) = vbNullString Then MkDir FolderCustomUI
    If Dir(SampleZIP) <> "" Then Kill SampleZIP: Do While Dir(SampleZIP) <> "": DoEvents: Loop
    If Dir(SampleC) <> "" Then Kill SampleC: Do While Dir(SampleC) <> "": DoEvents: Loop
    'creation du dossier de desipage temporaire
    If Dir(ProjetUI, vbDirectory) = vbNullString Then MkDir ProjetUI: Do While Dir(ProjetUI, vbDirectory) = vbNullString: DoEvents: Loop
    Application.DisplayAlerts = False
    Application.ScreenUpdating = False
    cdback = DocXml.generateCallBack
    
    'SI JE CLIK SUR CREATION
    If modecration = 1 Then
        Set wbk = Workbooks.Add
    Else 'sinon
        'boite de dialogue ici pour choisir un fichier [*.xls*] avec gestion d'annulation bien entendu
        ' la variable F  CONTIENT LE CHEMIN DU FICHIER  S2LECTIONN2
        Set wbk = Workbooks.Open(f)
    End If
'une fois le fichier excel ouvert on lui met le module callback et son code
    Set VBComp = wbk.VBProject.VBComponents.Add(1)
    VBComp.Name = "Modul_CallBack"
    VBComp.CodeModule.InsertLines 1, cdback
    DoEvents
    ActiveWorkbook.SaveAs Filename:=SampleC, FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
    Workbooks("Sample.xlsm").Close
    'gestion d'attente pour laisser Mac (ordinateur pour fille) le temps de bien créer le fichier
    Do While Dir(SampleC) = "": DoEvents: Loop
    Name SampleC As SampleZIP 'conversion en fichier ZIP
    'gestion d'attente pour laisser Mac (ordinateur pour fille) le temps de bien faire la conversion
    Do While Dir(SampleZIP) = "": DoEvents: Loop
'//////////////////////////////////////////////////////////////////
'MAINTENANT TU DEZIPPE ICI dans ProjetUI !!!!!!!
'ton applescript de dezippage ici!!!!!
'//////////////////////////////////////////////////////////////////
'apres dezippage tout se trouve dans le dossier projetUI
'on commence par modifier le customUI.xml
   'creation du dossier customui dazns projetUI
   MkDir ProjetUI & Application.PathSeparator & "customUI"
    'intégration
    Codxml = DocXml.GenerateXml
    Codxml = "<?xml version=""1.0"" encoding=""utf-8"" standalone=""yes""?>" & vbCrLf & Codxml
    MacSaveXmlFileUTF_8 Codxml, ProjetUI & Application.PathSeparator & "customUI" & Application.PathSeparator & "customUI14.xml"
'ENSUITE
 'modification du fichier rels
    x = FreeFile: Open ProjetUI & "\_rels\.rels" For Input As #x: Cod = Input$(LOF(x), #x): Close #x
    Q14 = "<Relationship Id=""custo14"" Type=""http://schemas.microsoft.com/office/2007/relationships/ui/extensibility"" Target=""customUI/customUI14.xml""/>"
    Cod = Replace(Cod, "</Relationships>", Q14 & vbCrLf & "</Relationships>")
    MacSaveXmlFileUTF_8 Cod, ProjetUI & Application.PathSeparator & "_rels" & Application.PathSeparator & ".rels"
'IL NE TE RESTE PLUS QU'A REZIPPER LE TOUT
'et enfin reconversion du zip en xlsm
 Name SampleZIP As SampleC
    MsgBox "Creation du classeur ""Sample.XLSM"" éffectuée"
   
   'suppression du dossier "projetUI" on en a plus besoins
    RmDir ProjetUI
End Sub