Closing an excel file?

jdlewin1

Registered User.
Local time
Today, 08:30
Joined
Apr 4, 2017
Messages
92
Hi All,

I have a command button which runs some code to export a query into excel and then open a few bits (not important for this).

If this is run again the code errors as the excel file is already open so the new one cant be opened with the new data. Is there a simple way to close the open excel file before the new one is open? I am presuming i need some sort of close command before the "DoCmd.OutputTo"?

Code behind the button below:

Code:
Private Sub Command40_Click()

DoCmd.OutputTo acOutputQuery, "TOA_Report_History", acFormatXLS, "C:\Users\jxl\Documents\querysave.xls", 1
DoCmd.OpenQuery "TOA_Report_History_Transpose_Delete"
DoCmd.OpenTable "TOA_Report_History_Transpose"

End Sub

Thank you.
 
Output should not open it. (Tho you may have a setting)
Docmd.transferspreadsheet doesn't either. (What I use)
But yes, Excel file must be closed to write to it.
 
Hi Ranman.

The code does open a sheet with that name. I want to make sure its closed before it runs the code?
 
Does it have to open? as your last parameter is doing that?
Hi Ranman.

The code does open a sheet with that name. I want to make sure its closed before it runs the code?
 
Yes as i need the information in it to be transposed in excel to then be copied back into access.

When i want to run this process again it errors as the excel sheet is open.
 

Users who are viewing this thread

Back
Top Bottom