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

  • Initiateur de la discussion Initiateur de la discussion BenHarber
  • Date de début Date de début

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

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...🙄

Merci d'avance pour votre aide 😉

BH
 
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:
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
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

  • Question Question
Réponses
7
Affichages
238
Réponses
10
Affichages
896
Réponses
32
Affichages
1 K
Retour