Bonjour, j'essaye de copier une feuille d'un classeur vers un autre classeur.
Rien de très compliquer donc, mais il y a un problème dans le code.
Il y a un problème sur cette ligne et plus particulièrement sur le fichier cilbe :
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 Sub AddNewWorkbook() Dim xlApp As Excel.Application Dim xlBook As Excel.Workbook Dim xlSheet As Excel.Worksheet Dim i, j, NbSheets, index(1 To 10) As Integer Dim SheetName(1 To 10) As String Dim fichier, Source As String Dim Results As Workbook Dim thisWorkbook As Workbook Source = ActiveWorkbook.Name j = 1 For i = 2 To 11 If IsEmpty(Sheets(i).Range("H2")) = False Then NbSheets = NbSheets + 1 SheetName(j) = Sheets(i).Name index(j) = i j = j + 1 End If Next i Set thisWorkbook = ActiveWorkbook Set xlApp = CreateObject("Excel.Application") xlApp.SheetsInNewWorkbook = NbSheets Set xlBook = xlApp.Workbooks.Add xlBook.SaveAs ("G:\Allianz\Allianz" & " " & Range("Undl") & " " & Range("Choice") & " " & Format(Date, "dd-mm-yy") & ".xls") xlApp.Visible = True fichier = xlBook.Name For i = 1 To NbSheets Set xlSheet = xlBook.Worksheets(i) xlSheet.Name = SheetName(i) Set xlSheet = Nothing Next i Workbooks(Source).Sheets(2).Copy After:=Workbooks(fichier).Sheets(2) End Sub
Il me marque une erreur du type : "Subscript out of range".
Code : Sélectionner tout - Visualiser dans une fenêtre à part Workbooks(Source).Sheets(2).Copy After:=Workbooks(fichier).Sheets(xlLast)
Si quelqu'un peut m'iader!
Merci d'avance.
Partager