Exportation Access vers Excel

Fermé
marachinaru Messages postés 3 Date d'inscription mercredi 6 août 2014 Statut Membre Dernière intervention 26 août 2014 - Modifié par pijaku le 7/08/2014 à 09:51
pijaku Messages postés 12263 Date d'inscription jeudi 15 mai 2008 Statut Modérateur Dernière intervention 4 janvier 2024 - 7 août 2014 à 09:54
Bonjour,

J'utilise VBA pour exporter à partir d'Access des données vers un excel mis en forme.
Cependant quand je lance l'exportation deux fois d'affilés, j'ai une erreur disant :

Erreur d'exécution '1004' :
« La méthode 'Cells' de l'objet'_Global' a échoué »

Cette erreur est sur la ligne en gras du code ci-dessous. Savez-vous comment rectifier cela ? Il doit falloir réinitialiser mais je n'y arrive pas.
C'est ici une partie de mon code mais le problème est seulement ici.
Merci d'avance.

Sub expExcel()

Dim appexcel As Excel.Application
Dim wbexcel As Excel.Workbook
Set appexcel = CreateObject("Excel.Application")
appexcel.Visible = True
Set wbexcel = appexcel.Workbooks.Open("C:\Users\moi\Documents\test.xlsx")
appexcel.Sheets("Feuil1").Select
appexcel.Cells(1, 1) = "Title"
appexcel.Range(Cells(1, 1), Cells(1, 6)).MergeCells = True
End Sub
A voir également:

1 réponse

pijaku Messages postés 12263 Date d'inscription jeudi 15 mai 2008 Statut Modérateur Dernière intervention 4 janvier 2024 2 743
7 août 2014 à 09:54
Bonjour,

appexcel est ta variable représentant l'application Excel, wbexcel ton classeur. Sert toi donc de la variable "classeru", comme ceci :

Sub expExcel()

Dim appexcel As Excel.Application
Dim wbexcel As Excel.Workbook
Set appexcel = CreateObject("Excel.Application")
appexcel.Visible = True
Set wbexcel = appexcel.Workbooks.Open("C:\Users\moi\Documents\test.xlsx")
With wbexcel.Sheets("Feuil1")
.Cells(1, 1) = "Title"
.Range(Cells(1, 1), Cells(1, 6)).MergeCells = True
End With
End Sub

0