Heidestrand
Registered User.
- Local time
- Today, 12:24
- Joined
- Apr 21, 2015
- Messages
- 73
Hello,
I'm using Access 2010 and I want to export a query to Excel by clicking a button. Every time I click on it Excel opens but doesn't open my worksheet, it's just gray like you just open the program without a table. After exiting it Access tells me I got a run time error 1004: the open-method of the workbook object couldn't be executed. After opening my Excel file it says that Excel found unreadable content and asks if I want to restore the content of the workbook.
Here is my code:
Does someone know where my problem is?
Best regards,
Heide
I'm using Access 2010 and I want to export a query to Excel by clicking a button. Every time I click on it Excel opens but doesn't open my worksheet, it's just gray like you just open the program without a table. After exiting it Access tells me I got a run time error 1004: the open-method of the workbook object couldn't be executed. After opening my Excel file it says that Excel found unreadable content and asks if I want to restore the content of the workbook.
Here is my code:
Code:
Private Sub Befehl62_Click()
Dim cdb As DAO.Database, qdf As DAO.QueryDef, SheetName As String, xlApp As Object
Set cdb = CurrentDb
Forms!Export_to_Excel!txtSheetName.SetFocus
SheetName = Me!txtSheetName.Text
Const xlsxPath = "\testchart.xlsx"
' create .xlsx file if it doesn't already exist, and add the first worksheet
Set qdf = cdb.CreateQueryDef("'" & SheetName & "'", _
"SELECT * FROM tblDetector")
Set qdf = Nothing
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "'" & SheetName & "'", xlsxPath, True
DoCmd.DeleteObject acQuery, "'" & SheetName & "'"
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
xlApp.Workbooks.Open "\testchart.xlsx", True
Debug.Print xlApp.Version
Set xlApp = Nothing
End Sub
Does someone know where my problem is?
Best regards,
Heide
Last edited: