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
| '--créer le fichier Excel
Set APP = CreateObject("Excel.application")
APP.Workbooks.Open Excel_OP, , False
Set rcd_data = CurrentDb.OpenRecordset(Ma_Requete)
'--compter le nombre de lignes
rcd_data.MoveLast
rcd_data.MoveFirst
MaxLigneRcd = rcd_data.RecordCount
MaxColonneRcd = rcd_data.Fields.Count
'--Parcours de la requête ligne par ligne
'APP.Visible = True
APP.Sheets(Nom_Onglet).Select
'--Insérer données à partir de la ligne 11 (exemple)...
With APP.Worksheets(Nom_Onglet)
For NumLigne = 11 To 10 + MaxLigneRcd
On Error GoTo erreur:
.Cells(NumLigne, 4) = rcd_data(0).Value
.Cells(NumLigne, 5) = rcd_data(1).Value
Nb_Lignes = Nb_Lignes + 1
On Error GoTo erreur:
rcd_data.MoveNext
Next NumLigne
End With |