[Access] pilotage excel
enigmatoile
Messages postés
730
Statut
Membre
-
enigmatoile Messages postés 730 Statut Membre -
enigmatoile Messages postés 730 Statut Membre -
Bonjour,
Depuis Access, je souhaite ouvrir un claseur Excel; mettre des infos dedans puis le sauvegarder sous un autre nom.
J'ai une erreur au moment de la sauvegarde : 'Variable objet ou vriable de bloc With non définie'
Voici mon code
Private Sub btn_test_Click()
On Error GoTo Err_btn_test_Click
Dim xlApp As Excel.Application
Dim xlw As Excel.Workbook
Dim xls As Excel.Worksheet
Dim rst As DAO.Recordset
Dim strFichier As String
'Démarrage d'Excel
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
'Création d'un classeur
Excel.Workbooks.Open ("C:\monchemin\modelebis.xls")
'Ouverture de la requete rqt_toto
Set rst = CurrentDb.OpenRecordset("rqt_toto")
'Transfert de données
xlApp.Range("B14").CopyFromRecordset rst
'Sauvegarde et fermeture
strFichier = "C:\monchemin\modelebis.xls"
xlw.SaveAs strFichier
xlApp.Quit
Set xls = Nothing
Set xlw = Nothing
Set xlApp = Nothing
Exit_btn_test_Click:
Exit Sub
Err_btn_test_Click:
Set xls = Nothing
Set xlw = Nothing
Set xlApp = Nothing
MsgBox Err.Description
Resume Exit_btn_test_Click
End Sub
Pouvez vous m'aider?
Depuis Access, je souhaite ouvrir un claseur Excel; mettre des infos dedans puis le sauvegarder sous un autre nom.
J'ai une erreur au moment de la sauvegarde : 'Variable objet ou vriable de bloc With non définie'
Voici mon code
Private Sub btn_test_Click()
On Error GoTo Err_btn_test_Click
Dim xlApp As Excel.Application
Dim xlw As Excel.Workbook
Dim xls As Excel.Worksheet
Dim rst As DAO.Recordset
Dim strFichier As String
'Démarrage d'Excel
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
'Création d'un classeur
Excel.Workbooks.Open ("C:\monchemin\modelebis.xls")
'Ouverture de la requete rqt_toto
Set rst = CurrentDb.OpenRecordset("rqt_toto")
'Transfert de données
xlApp.Range("B14").CopyFromRecordset rst
'Sauvegarde et fermeture
strFichier = "C:\monchemin\modelebis.xls"
xlw.SaveAs strFichier
xlApp.Quit
Set xls = Nothing
Set xlw = Nothing
Set xlApp = Nothing
Exit_btn_test_Click:
Exit Sub
Err_btn_test_Click:
Set xls = Nothing
Set xlw = Nothing
Set xlApp = Nothing
MsgBox Err.Description
Resume Exit_btn_test_Click
End Sub
Pouvez vous m'aider?
A voir également:
- [Access] pilotage excel
- Liste déroulante excel - Guide
- Word et excel gratuit - Guide
- Si ou excel - Guide
- Déplacer colonne excel - Guide
- Comment trier par ordre alphabétique sur excel - Guide
Ligne posnat problème : xlw.SaveAs strFichier
Message d'erruer : 'Variable objet ou vriable de bloc With non définie'