s = Feuil4.[A1]
r = Feuil23.[c2]
If Dir("C:\Users\" & s & "\dropbox\joueurs\" & r, vbDirectory) = "" Then _
MkDir "C:\Users\" & s & "\dropbox\joueurs\" & r
' CREER UN CLASSEUR dans le dossier
Application.ScreenUpdating = False
xnomfic = Range("C2"): ficd = xnomfic & " Musculation.xlsx": xcell = Range("F2"): xnomsh = Replace(xcell, "/", "")
' CREER UN CLASSEUR
Application.ScreenUpdating = False
xnomfic = Range("C2"): ficd = xnomfic & " Musculation.xlsx": xcell = Range("F2"): xnomsh = Replace(xcell, "/", "")
' Contrôle de l'existence du fichier ou classeur
If FichierExiste("C:\users\" & s & "\dropbox\joueurs\" & r & "\" & ficd) = "Vrai" Then ' MODIFIER LE CHEMIN DU REPERTOIRE - SI NECESSAIRE
' ------------------------------------------------------------------------------------------------------------------
' Le classeur existe - On recherche si la feuille existe
[COLOR="#FF0000"]Workbooks.Open ("C:\users\" & s & "\dropbox\joueurs\" & r & "\" & ficd), UpdateLinks:=0: Workbooks(ficd).Activate ' MODIFIER LE CHEMIN DU REPERTOIRE - SI NECESSAIRE
Workbooks("Musculation.xlsm").Sheets("Modele").Range("A4:R34").Copy
With ActiveWorkbook.Sheets(xnomsh)
.Rows("34:100").RowHeight = 13
.Range("A4:R34").Rows(Sheets(xnomsh).Range("A" & Rows.Count).End(xlUp).Row + 1).Insert
End With
MsgBox "Sauvegarde " & r & " effectuée."
ActiveWorkbook.Save
ActiveWorkbook.Close
Else[/COLOR]
' Le classeur existe - On ajoute la feuille
Worksheets.Add After:=Sheets((Sheets.Count)): Worksheets(Sheets.Count).Name = xnomsh
Workbooks("Musculation.xlsm").Sheets("Modele").Range("A:AG").Copy
With ActiveWorkbook.Sheets(xnomsh)
.Rows("4:34").RowHeight = 13
.Range("A:AG").PasteSpecial Paste:=xlPasteValues
.Range("A:AG").PasteSpecial Paste:=xlPasteFormats
.Range("A:AG").PasteSpecial Paste:=xlPasteColumnWidths
Workbooks("Musculation.xlsm").Sheets("Modele").Range("O4:R34").Copy
With ActiveWorkbook.Sheets(xnomsh)
.Range("O4:R34").PasteSpecial Paste:=xlPasteFormulas
.Range("A1").Select
End With
End With
ActiveWindow.DisplayHeadings = False
Application.DisplayFullScreen = True
Application.CutCopyMode = False
ActiveWindow.DisplayZeros = False
ActiveWindow.DisplayGridlines = False
MsgBox "Sauvegarde " & r & " effectuée."
ActiveWorkbook.Save
ActiveWorkbook.Close
End If
' ------------------------------------------------------------------------------------------------------------------
Else
'___________________________________________________________________________________________________________________
' Création du fichier ou classeur et copie de la feuille modele
Workbooks.Add
Workbooks("Musculation.xlsm").Sheets("Modele").Range("A:AG").Copy
With ActiveWorkbook.Sheets("Feuil1")
.Rows("4:34").RowHeight = 13
.Range("A:AG").PasteSpecial Paste:=xlPasteValues
.Range("A:AG").PasteSpecial Paste:=xlPasteFormats
.Range("A:AG").PasteSpecial Paste:=xlPasteColumnWidths
Workbooks("Musculation.xlsm").Sheets("Modele").Range("O4:R25").Copy
With ActiveWorkbook.Sheets("Feuil1")
.Range("O4:R25").PasteSpecial Paste:=xlPasteFormulas
.Range("A1").Select
End With
End With
ActiveWindow.DisplayHeadings = False
Application.DisplayFullScreen = True
Application.CutCopyMode = False
ActiveWindow.DisplayZeros = False
ActiveSheet.Name = xnomsh
ActiveWorkbook.SaveAs Filename:="C:\users\" & s & "\dropbox\joueurs\" & r & "\" & xnomfic & " Musculation.xlsx" ' MODIFIER LE CHEMIN DU REPERTOIRE - SI NECESSAIRE
ActiveWorkbook.Close
MsgBox "Le Dossier " & r & " a bien été créé."
'End If
End If
'ActiveWindow.SelectedSheets.PrintOut from:=1, To:=1, copies:=1, collate:=0
'___________________________________________________________________________________________________________________
Application.ScreenUpdating = True
End Sub
Function FichierExiste(ficd) As Boolean
FichierExiste = Dir(ficd) <> "" And ficd <> ""
End Function
Cordialement
jujunexcelpas