Bonjour,

J'ai développé une macro qui reprend exactement une autre macro dévelopé par un collègue.
Les deux macros appels deux procédures stockées sous SQL Server qui font exactement la même chose, sur des périmètres différents (même paramètres, même sorties).
Les deux macros marchent dans mon service mais la mienne ne marche pas dans le service des utilisateurs et renvoie ce message:
Erreur: impossible de trouver l'objet dans la collection correspondant au nom ou à la réference ordinale demandé.

On ne comprend vraiment pas ce qui pourrait causer cela.

Voici les macros:

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
Option Explicit
 
Sub Bouton1_Clic()
    Dim datobs As Date
 
    Application.ScreenUpdating = False
    datobs = Sheets("Pilotage").Cells(1, 2)
    Sheets("Sensi").Cells.Clear
 
    AIF_REP_RatingMoyenSensi "Sensi", datobs
    Application.ScreenUpdating = True
 
End Sub
 
 
 
Sub Bouton2_Clic()
    Dim datobs As Date
 
    Application.ScreenUpdating = False
    datobs = Sheets("Pilotage").Cells(1, 2)
    Sheets("SensiAll").Cells.Clear
    AIF_REP_RatingMoyenSensiAll "SensiAll", datobs
    Application.ScreenUpdating = True
End Sub
 
 
 
Sub AIF_REP_RatingMoyenSensi(ByVal classeur_feuille As String, Optional ByVal datobs As Date)
 
Dim varRecords() As Variant
Dim varRecordsTranspose As Variant
Dim j As Integer
 
    On Error GoTo gestionErr
 
    Application.StatusBar = "Rating Moyen"
 
    If cnx Is Nothing Then initializeConnection
    If cnx.State <> 1 Then initializeConnection
 
    Set cmd = New ADODB.Command
 
    cmd.ActiveConnection = cnx
    cmd.CommandType = adCmdStoredProc
    cmd.CommandText = "s_REP_RatingMoyenSensi"
 
    cmd.Parameters.Refresh
 
    If Len(datobs) > 1 And Left(datobs, 2) <> "00" Then
        cmd.Parameters.Item(1).Value = datobs
    End If
 
    Set rst = cmd.Execute
    If rst.BOF = True Then
        GoTo gestionVide
    End If
 
    Sheets(classeur_feuille).Select
 
    varRecords = rst.GetRows
 
    ActiveSheet.Range(Cells(1, 1), Cells(1, UBound(varRecords) + 1)).EntireColumn.Clear
 
    varRecordsTranspose = TransposeDim(varRecords)
 
    ActiveSheet.Range("A3").Resize(UBound(varRecords, 2) + 1, UBound(varRecords, 1) + 1).Value = varRecordsTranspose
 
 
    For j = 0 To rst.Fields.Count - 1
        Cells(1, j + 1) = rst.Fields.Item(j).Name
    Next j
 
    Set cmd = Nothing
    Set rst = Nothing
 
    Application.StatusBar = ""
 
    Exit Sub
 
gestionVide:
 
    Set cmd = Nothing
    Set rst = Nothing
 
    Sheets(classeur_feuille).Select
    ActiveSheet.Cells.Clear
 
    Cells(1, 1) = "Aucun enregistrement correspondant"
    Application.StatusBar = ""
 
    Exit Sub
 
 
gestionErr:
 
    Set cmd = Nothing
    Set rst = Nothing
 
    Sheets(classeur_feuille).Select
    ActiveSheet.Cells.Clear
 
    Cells(1, 1) = "Erreur : " & Err.Description
    Application.StatusBar = ""
 
End Sub
 
 
 
 
Sub AIF_REP_RatingMoyenSensiAll(ByVal classeur_feuille As String, Optional ByVal datobs As Date)
 
Dim varRecords() As Variant
Dim varRecordsTranspose As Variant
Dim j As Integer
 
    On Error GoTo gestionErr
 
    Application.StatusBar = "Rating Moyen"
 
    If cnx Is Nothing Then initializeConnection
    If cnx.State <> 1 Then initializeConnection
 
    Set cmd = New ADODB.Command
 
    cmd.ActiveConnection = cnx
    cmd.CommandType = adCmdStoredProc
    cmd.CommandText = "s_REP_RatingMoyenSensiAll"
 
    cmd.Parameters.Refresh
 
    If Len(datobs) > 1 And Left(datobs, 2) <> "00" Then
        cmd.Parameters.Item(1).Value = datobs
    End If
 
    Set rst = cmd.Execute
    If rst.BOF = True Then
        GoTo gestionVide
    End If
 
    Sheets(classeur_feuille).Select
 
    varRecords = rst.GetRows
 
    ActiveSheet.Range(Cells(1, 1), Cells(1, UBound(varRecords) + 1)).EntireColumn.Clear
 
    varRecordsTranspose = TransposeDim(varRecords)
 
    ActiveSheet.Range("A3").Resize(UBound(varRecords, 2) + 1, UBound(varRecords, 1) + 1).Value = varRecordsTranspose
 
 
    For j = 0 To rst.Fields.Count - 1
        Cells(1, j + 1) = rst.Fields.Item(j).Name
    Next j
 
    Set cmd = Nothing
    Set rst = Nothing
 
    Application.StatusBar = ""
 
    Exit Sub
 
gestionVide:
 
    Set cmd = Nothing
    Set rst = Nothing
 
    Sheets(classeur_feuille).Select
    ActiveSheet.Cells.Clear
 
    Cells(1, 1) = "Aucun enregistrement correspondant"
    Application.StatusBar = ""
 
    Exit Sub
 
 
gestionErr:
 
    Set cmd = Nothing
    Set rst = Nothing
 
    Sheets(classeur_feuille).Select
    ActiveSheet.Cells.Clear
 
    Cells(1, 1) = "Erreur : " & Err.Description
    Application.StatusBar = ""
 
End Sub
Merci par avance,
Je suis tout nouveau sur ce forum et je n'ai pas trouvé comme joindre les macros pour qu'elle s'affiche comme dans les autres posts.