Opening an Excel file from Access

  • Thread starter Thread starter Tamer Seoud
  • Start date Start date
T

Tamer Seoud

I created a user interface to view and print out reports.
One of reports needed to be viewed in Excel. I need to
open the excel sheet and output the query result from a
command's event click. The code I used returns error
message. Please advise. Thanks a million

The following is the code I used

Private Sub lbl_OpenSE_Rpt_Click()
Dim ExcelObj As Object
Set ExcelObj = CreateObject("Excel.Application")
ExcelObj.spreadsheet.Open "F:\ExcelTest.xls"
DoCmd.OutputTo acQuery, "qry_SE_Info", "MicrosoftExcel
(*.xls)", "F:\ExcelTest.xls", False, ""
 
I tried just following line. It works fine. It creates a
new file though.

DoCmd.OutputTo acQuery, "RohToolingTimeExcel_qry",
acFormatXLS, "F:\ExcelTest.xls", -1
 
hi tamer,

i think you would need to use: DoCmd.TransferSpreadsheet method. This will
output your query to a predefined spreadsheet.

something like:

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "dalequery",
"C:\temp\lisa.xls"

This would transfer the dalequery to the lisa spreadsheet.

other than that, another way would be to finish calling the excel object
model. more complicated but doable....

HTH

Nathan
Software Test Lead
www.skylineprints.com
 
Back
Top