Exportation Access vers Excel

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

1 réponse

  1. Modérateur
    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

    Discussions similaires

    Quick Access service

    4 réponses