Private Sub CommandButton1_Click() 'Valider
TextBox1 = Application.Trim(TextBox1): TextBox2 = Application.Trim(TextBox2)
If TextBox1 = "" Then TextBox1.SetFocus: Exit Sub
If TextBox2 = "" Then TextBox2.SetFocus: Exit Sub
If ComboBox1.ListIndex = -1 Then ComboBox1.DropDown: Exit Sub
Dim chemin$, modele$, fich$
chemin = ThisWorkbook.Path & "\" 'à adapter
modele = "Modele.xltm"
fich = chemin & ComboBox1 & " " & TextBox1 & " Classe " & TextBox2 & ".xlsm" 'à adapter
If Dir(fich) <> "" Then MsgBox "Cette classe a déjà été créée !", 48: Exit Sub
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.EnableEvents = False
On Error Resume Next
With Workbooks.Open(chemin & modele)
With .Sheets("1er Trim")
.[B1] = TextBox1
.[Q4] = TextBox2
.[P3] = ComboBox1
End With
.SaveAs fich, FileFormat:=xlOpenXMLWorkbookMacroEnabled '52
.Close
End With
Application.EnableEvents = True
Application.ScreenUpdating = True
If Dir(fich) <> "" Then MsgBox "La classe de " & TextBox2 & " a bien été créée..."
End Sub
Private Sub UserForm_Initialize()
Dim i%
For i = 2015 To 2024
ComboBox1.AddItem i & " - " & i + 1
Next
End Sub