Bonjour,


J'ai un problème avec un fichier excel que l'on vient de me donner, c'est un tableau d'inscription à des formations, je pense qu'il y a un problème d'adressage de fichier référent.


Voici le message d'erreur:
erreur d'execution '1004'
Impossible de renommer une feuille comme une autre feuille, une bibliotheque d'objets référencée ou un classeur référencée par Visual Basic
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
Sub generer_planning()

'Création de la feuille
Sheets("modele").Select
Sheets("modele").Copy , Sheets(Sheets.Count)
Sheets(Sheets.Count).Name = "Plannings"

'ouverture des données
ChDir "U:\YMAG WIN FC\Macros excel\extractions"
    Workbooks.OpenText Filename:="U:\YMAG WIN FC\Macros excel\extractions\jour.txt", _
        Origin:=xlWindows, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
        xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
        Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(1, 1)
    Cells.Select
    Selection.Copy
    Windows("planning_salle.xls").Activate
    Worksheets("data").Select
    Cells.Select
    ActiveSheet.Paste
    Windows("jour.txt").Activate
    ActiveWindow.Close

'Récupération de la date
Sheets("data").Select
ladate = CDate(Mid(Cells(4, 1).Value, 12, 10))
Sheets("planning").Select
Cells(1, 1).Value = Format(ladate, "Dddd dd mmmm yyyy")

'décompte du nombre de lignes
Sheets("data").Select
comptelignes = 0
While Cells(comptelignes + 8, 1) <> ""
comptelignes = comptelignes + 1
Wend

'tri des données

Range("A8:R" & comptelignes + 7).Select
    Selection.Sort Key1:=Range("R8"), Order1:=xlAscending, Key2:=Range("B8") _
        , Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
        False, Orientation:=xlTopToBottom
    ActiveWindow.ScrollColumn = 10

'copie des données Salles
Range("Q8:Q" & comptelignes + 7).Select
Selection.Copy
Sheets("planning").Select
Range("A3:A" & comptelignes + 2).Select
ActiveSheet.Paste

'copie des données Stages
Sheets("data").Select
Range("J8:J" & comptelignes + 7).Select
Selection.Copy
Sheets("planning").Select
Range("B3:B" & comptelignes + 2).Select
ActiveSheet.Paste

'copie des données Session
Sheets("data").Select
Range("L8:L" & comptelignes + 7).Select
Selection.Copy
Sheets("planning").Select
Range("C3:C" & comptelignes + 2).Select
ActiveSheet.Paste

'Copie des heures de début
Sheets("data").Select
For i = 1 To comptelignes
If Cells(i + 7, 3).Value = 0 Then
Cells(i + 7, 19).Value = Cells(i + 7, 2).Value & "h00"
Else
Cells(i + 7, 19).Value = Cells(i + 7, 2).Value & "h" & Cells(i + 7, 3)
End If
Next
Range("S8:S" & comptelignes + 7).Select
Selection.Copy
Sheets("planning").Select
Range("E3:E" & comptelignes + 2).Select
ActiveSheet.Paste

'Copie des heures de fin
Sheets("data").Select
For i = 1 To comptelignes
If Cells(i + 7, 5).Value = 0 Then
Cells(i + 7, 20).Value = Cells(i + 7, 4).Value & " h 00"
Else
Cells(i + 7, 20).Value = Cells(i + 7, 4).Value & " h " & Cells(i + 7, 5)
End If
Next
Range("T8:T" & comptelignes + 7).Select
Selection.Copy
Sheets("planning").Select
Range("F3:F" & comptelignes + 2).Select
ActiveSheet.Paste

'copie des formateurs
For k = 1 To comptelignes
Sheets("data").Select
codeform = Cells(k + 7, 13).Value
Sheets("Formateurs").Select
i = 2
Do While Cells(i, 1) <> ""
If Cells(i, 1).Value = codeform Then
formateur = Cells(i, 2).Value & " " & Cells(i, 4).Value & " " & Cells(i, 3).Value
Sheets("data").Select
Cells(k + 7, 21).Value = formateur
Exit Do
Else
i = i + 1
End If
Loop
Next
Sheets("data").Select
Range("U8:U" & comptelignes + 7).Select
Selection.Copy
Sheets("planning").Select
Range("D3:D" & comptelignes + 2).Select
ActiveSheet.Paste

'Mise en forme tableau

'Lignes
Range("A3:F" & comptelignes + 2).Select
    Selection.Borders(xlEdgeRight).LineStyle = xlNone
    Selection.Borders(xlInsideVertical).LineStyle = xlNone
    Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    Selection.Borders(xlEdgeLeft).LineStyle = xlNone
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    Selection.Borders(xlEdgeRight).LineStyle = xlNone
    Selection.Borders(xlInsideVertical).LineStyle = xlNone
    With Selection.Borders(xlInsideHorizontal)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With

'Pagination des colonnes
    Columns("A:A").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlVAlignCenter
        .WrapText = False
        .Orientation = 0
        .ShrinkToFit = False
        .MergeCells = False
    End With
    
    Columns("B:B").Select
    With Selection
        .HorizontalAlignment = xlRight
        .VerticalAlignment = xlVAlignCenter
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        End With
    
    Range("C:C").Select
    With Selection
        .HorizontalAlignment = xlLeft
        .VerticalAlignment = xlVAlignCenter
        .WrapText = False
        .Orientation = 0
        .IndentLevel = 0
        .ShrinkToFit = False
    End With
    
    Range("D:D").Select
    With Selection
        .VerticalAlignment = xlVAlignCenter
        .WrapText = True
        .Orientation = 0
        .ShrinkToFit = False
    End With
    
    Range("E:E").Select
    With Selection
        .HorizontalAlignment = xlRight
        .VerticalAlignment = xlVAlignCenter
        .WrapText = False
        .Orientation = 0
        .ShrinkToFit = False
    End With
    
  Columns("F:F").Select
    With Selection
        .HorizontalAlignment = xlLeft
        .VerticalAlignment = xlVAlignCenter
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        End With
        
 'Pagination du titre
    Range("A1:F1").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlVAlignCenter
        .Orientation = 0
        .ShrinkToFit = False
    End With
    Selection.Merge
    
 'Mise en page : Marges, Impression sur une page
    ActiveWindow.ScrollColumn = 2
    ActiveWindow.ScrollColumn = 1
    
    With ActiveSheet.PageSetup
        .PrintTitleRows = ""
        .PrintTitleColumns = ""
    End With
    ActiveSheet.PageSetup.PrintArea = ""
    With ActiveSheet.PageSetup
        .LeftHeader = ""
        .CenterHeader = ""
        .RightHeader = ""
        .LeftFooter = ""
        .CenterFooter = ""
        .RightFooter = ""
        .LeftMargin = Application.InchesToPoints(0)
        .RightMargin = Application.InchesToPoints(0)
        .TopMargin = Application.InchesToPoints(0)
        .BottomMargin = Application.InchesToPoints(0)
        .HeaderMargin = Application.InchesToPoints(0)
        .FooterMargin = Application.InchesToPoints(0)
        .PrintHeadings = False
        .PrintGridlines = False
        .PrintComments = xlPrintNoComments
        .CenterHorizontally = True
        .CenterVertically = True
        .Orientation = xlLandscape
        .Draft = False
        .PaperSize = xlPaperA4
        .FirstPageNumber = xlAutomatic
        .Order = xlDownThenOver
        .BlackAndWhite = False
        .Zoom = False
        .FitToPagesWide = 1
        .FitToPagesTall = 1
    End With

MsgBox "Attention! Ne pas sauvegarder ce classeur après utilisation"
End Sub
Ligne incriminé en gras