Au début je fais comme ceci:
Set rec = Forms.formulaire.sous-formulaire.Form.RecordsetClone
Je remplis mon recordset avec tout le sous-formulaire, car je souhaite tout exporter.
Voilà le code entier si ça peut aider :
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
| Function exportexcelvb()
Dim appexcel As Excel.Application
Dim wbexcel As Excel.Workbook
Dim rec As DAO.Recordset
Set rec = Forms.formulaire.sous-formulaire.Form.RecordsetClone
Set appexcel = CreateObject("Excel.Application")
appexcel.Visible = True
Set wbexcel = appexcel.Workbooks.Open(CurrentProject.Path & "\classeur01.xls")
appexcel.Sheets("Feuille1").Select
'Exportation du recordset ss formulaire
appexcel.Cells(58, 2).CopyFromRecordset rec
rec.MoveFirst
' Ferme les objets ADO
rec.Close
Set rec = Nothing
Set wbexcel = Nothing
Set appexcel = Nothing
End Function |
Partager