Error 3011 when exporting access data to excel

0

Good morning. I have a problem when I try to generate an excel from an access table (2010). I have the following code.

Dim outputFileName As String
Dim objExcel As Object 'New Excel.Application
Dim objWB As Object 'Workbook
'Nombre del archivo de salida
outputFileName = CurrentProject.Path & "\Salida\Cartelera_" & Format(Date, "yyyyMMdd") & "_" & Format(Time, "HHmmss") & ".xlsx"
FileCopy CurrentProject.Path & "\PlantillaCartelera.xlsx", outputFileName

Set objExcel = CreateObject("Excel.Application")
Set objWB = objExcel.Workbooks.Open(outputFileName)

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "temp", outputFileName, False
objWB.ActiveSheet.Select
'objWB.Worksheets("Datos").Visible = False
'objExcel.Visible = True
Set objExcel = Nothing

When I execute it, the following error message appears

  

The '3011' error occurred at runtime:   The Microsoft Office database engine could not find the 'temp' object. Make sure that the object exists and that you have written the name and path of the object correctly. If 'temp' is not a local object, check the network connection or contact the server administrator.

The route is well defined because if I create the excel file where I want to insert the table "temp" and the table 'temp' if it has records. Can someone help me?

    
asked by user7395552 06.02.2017 в 11:13
source

1 answer

0

What you are indicating in TransferSpreadsheet with temp is a text string, without more, you have it in quotes.

You will have to include the complete path:

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "C:\user\dir\dir2\...", outputFileName, False

You have more information on the msdn website .

    
answered by 06.02.2017 / 11:28
source