1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
Sub AddNewWorkbook()
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
'On crée l'objet Excel
Set xlApp = CreateObject("Excel.Application")
'On définit le nombre d'onglets (ici 5)
xlApp.SheetsInNewWorkbook = 5
'On ajoute un classeur
Set xlBook = xlApp.Workbooks.Add
'On donne un nom au classeur
'xlBook.SaveAs (Workbooks(ActiveWorkbook.Name).Path & Application.PathSeparator & "Mes Menus.xls")
xlBook.SaveAs Filename:=(Workbooks(ActiveWorkbook.Name).Path & Application.PathSeparator & "Mes_Menus.xlsm"), FileFormat:= _
xlOpenXMLWorkbookMacroEnabled
'On rend le classeur visible
xlApp.Visible = True
'On créer l'objet onglet dans le nouveau classeur créé
Set xlSheet = xlBook.Worksheets(1)
'On affecte un nom aux l'onglets
xlSheet.Name = "Semaine1"
'xlSheet.Activate
xlSheet.Range("A1:V22").Value = ThisWorkbook.Worksheets("EdT").Range("A1:V22").Value
xlSheet.Range("A3:V22").Select
Application.Run "Projet.xlsm!Format_Tab_Se"
'on libère l'objet onglet pour pouvoir en créer un nouveau ... etc
Set xlSheet = Nothing
'
Set xlSheet = xlBook.Worksheets(2)
xlSheet.Name = "Semaine2"
xlSheet.Range("A1:V22").Value = ThisWorkbook.Worksheets("EdT").Range("A1:V22").Value
Set xlSheet = Nothing
'
Set xlSheet = xlBook.Worksheets(3)
xlSheet.Name = "Semaine3"
xlSheet.Range("A1:V22").Value = ThisWorkbook.Worksheets("EdT").Range("A1:V22").Value
Set xlSheet = Nothing
Set xlSheet = xlBook.Worksheets(4)
xlSheet.Name = "Semaine4"
xlSheet.Range("A1:V22").Value = ThisWorkbook.Worksheets("EdT").Range("A1:V22").Value
Set xlSheet = Nothing
Set xlSheet = xlBook.Worksheets(5)
xlSheet.Name = "Mois"
Set xlSheet = Nothing
'On remet la propriété de l'application à 3 (par défaut)
xlApp.SheetsInNewWorkbook = 3
'On ferme l'application
xlApp.Quit
End Sub |
Partager