Bonjour le forum,

Je viens à nouveau vers vous car j'ai une petite incompréhension et j'aurais besoins d'un éclaircissement.
Dans un premier temps voici mes codes :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
Public Commande As String
Public Datec As String
Public Nomcde As String
Public Cheminc As String
Public Nomc As String
Public yc As Integer
Public Nbc As String
Public dicoc As New Dictionary
Public Wb As String
 
Sub essai()
Wb = ActiveWorkbook.Name
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim Repertoire As FileDialog
 
For y = 1 To Cells(50, Cells.Columns.Count).End(xlToLeft).Column
If Not dicoc.Exists(Cells(50, y).Value) Then
dicoc.Add Cells(50, y).Value, Cells(50, y).Column - a
a = y
End If
Next y
 
NCom.Show
 
Set xlApp = CreateObject("Excel.Application")
    xlApp.SheetsInNewWorkbook = dicoc.Count
Set xlBook = xlApp.Workbooks.Add
    xlBook.SaveAs (Cheminc & "\- X - " & Commande & " - Truc.xls")
    xlApp.Visible = True
    Nomc = "- X - " & Commande & " - Truc.xls"
 
For yc = 1 To dicoc.Count
Nbc = dicoc("cellule " & yc)
Set xlSheet = xlBook.Worksheets(yc)
xlSheet.Name = "Cellule " & yc
Sheets(yc).Activate
Call Mise_en_page
Call Mise_en_paquet
Set xlSheet = Nothing
Next yc
 
End Sub
Suivi de (dans le même module) :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Sub Mise_en_page()
 
    Workbooks(Nomc).Sheets(yc).Columns("A:M").ColumnWidth = 12
    Workbooks(Nomc).Sheets(yc).Columns("F:F").ColumnWidth = 2.29
    Workbooks(Nomc).Sheets(yc).Range("E1:H2").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = True
        .MergeCells = True
        .Font.Size = 16
    End With
 
    Workbooks(Nomc).Sheets(yc).Range("B6").FormulaR1C1 = "CDE :": Workbooks(Nomc).Sheets(yc).Range("B6").Font.Size = 14: Workbooks(Nomc).Sheets(yc).Range("C6").Value = Commande
    Workbooks(Nomc).Sheets(yc).Range("B7").FormulaR1C1 = "Chantier :": Workbooks(Nomc).Sheets(yc).Range("B7").Font.Size = 14: Workbooks(Nomc).Sheets(yc).Range("C7").Value = Nomcde
    Workbooks(Nomc).Sheets(yc).Range("B10").FormulaR1C1 = "Sortie :": Workbooks(Nomc).Sheets(yc).Range("B10").Font.Bold = True: Workbooks(Nomc).Sheets(yc).Range("B10").Font.Size = 14
    Workbooks(Nomc).Sheets(yc).Range("D10").FormulaR1C1 = "Nb colis :": Workbooks(Nomc).Sheets(yc).Range("E10").FormulaR1C1 = Nbc
    Workbooks(Nomc).Sheets(yc).Range("E11").FormulaR1C1 = "Rq :": Workbooks(Nomc).Sheets(yc).Range("E11").Font.Bold = True
    Workbooks(Nomc).Sheets(yc).Range("F11").FormulaR1C1 = "1 latte ": Workbooks(Nomc).Sheets(yc).Range("F11").Font.Bold = True
    Workbooks(Nomc).Sheets(yc).Range("E1").FormulaR1C1 = "Schéma"
 
End Sub
Comme on peut le voir j'utilise une variable (Nomc) pour sauvegarder le nom du nouveau classeur créé. Or quand je l'a réutilise dans la macro Mise_en_page il me dit : "Erreur 9 : l'indice n'appartient pas à la sélection"

Donc si quelqu'un à une petite idée merci à lui