XL 2013 Code VBA pr nouveau fichier avec un nombre d'onglets prédéfini ?

BenHarber

XLDnaute Occasionnel
Bonjour le Forum,
Connaissez-vous le code VBA qui me permette de créer un fichier avec un nombre d'onglets prédéfini ?
Par ex. je souhaite créer un nouveau fichier avec 6 onglets, un code du style :
Workbooks.Add (6)
Mais bon....ça, ça ne fonctionne pas...:rolleyes:

Merci d'avance pour votre aide ;)

BH
 

ChTi160

XLDnaute Barbatruc
Bonjour
une recherche m'a permis de trouver ceux ci.(à adapter)
VB:
'Code VBA: Créer un nouveau classeur avec un nombre spécifique de feuilles de calcul
Sub MakeWorkbook()
    Dim xOldCount As Integer
    Dim xNewCount As Variant
    xOldCount = Application.SheetsInNewWorkbook
    xNewCount = Application.InputBox("How many sheets in the new workbook do you want?", "Kutools for Excel", , , , , , 1)
    If xNewCount = False Then Exit Sub
    If (xNewCount < 1) Or (CLng(xNewCount) > 255) Then
        MsgBox "The number must between 1 and 255!"
        Exit Sub
    End If
    With Application
        .SheetsInNewWorkbook = xNewCount
        .Workbooks.Add
        .SheetsInNewWorkbook = xNewCount
    End With
End Sub
edit : (il y a sûrement d'autres procédures!)
Le Lien :
Bonne journée
jean marie
 
Dernière édition:

ChTi160

XLDnaute Barbatruc
Bonjour BenHarder
Bonjour le Fil (Jean-Eric), le Forum
soit :
VB:
Sub MakeWorkbook()
    Dim xOldCount As Integer
    Dim xNewCount As Variant
    xOldCount = Application.SheetsInNewWorkbook 'Valeur initiale
    xNewCount = Application.InputBox("How many sheets in the new workbook do you want?", "Kutools for Excel", , , , , , 1)
    If xNewCount = False Then Exit Sub
    If (xNewCount < 1) Or (CLng(xNewCount) > 255) Then
        MsgBox "The number must between 1 and 255!"
        Exit Sub
    End If
    With Application
        .SheetsInNewWorkbook = xNewCount
        .Workbooks.Add
        .SheetsInNewWorkbook =  xOldCount 'Ici remise à la valeur initiale
    End With
End Sub
Merci Jean-Eric
jean marie
 

Discussions similaires

Statistiques des forums

Discussions
312 198
Messages
2 086 148
Membres
103 131
dernier inscrit
diaz.evelyne17