Excel Application

  • Thread starter Thread starter Martin
  • Start date Start date
M

Martin

I have the following code in Access that is used to open an Excel file, do
some work with that file, then close the file and the Excel application.

Dim xlApp As Excel.Application
Set xlApp = CreateObject("Excel.Application")

xlApp.Workbooks.Open FileName:=HRFileName
With xlApp

[Work with the Excel file]


'Close HR File
.Workbooks(HRFile).Close False

End With

' Close Excel with the Quit method on the Application object.
xlApp.Quit
' Release the object variable.
Set xlApp = Nothing

Everything works fine except that after the script is completed, the Excel
application is open in the Windows Taskbar with the spreadsheet open in
Read-only mode.

Can someone offer some directioin as to how to stop this? It is annoying
for the end-user to have to close Excel after this script is done.

Thanks.
 
As posted, the code appears to be correct. The problem most likely exists in
the unposted code.

The most usual cause of the Excel app not closing is an incorrect or
incomplete object reference. When using Automation it is critical to fully
qualify all your object references. If Access can't determine an Automation
ojbect reference, it will create another Excel Application object on its own
and use that. So when you Quit, you quit one, but not the other.

Check all your object references to be sure every object created refers all
the way back to the original Excel Application object.
 
Thanks for the reply. I will dig back thru the references.


Klatuu said:
As posted, the code appears to be correct. The problem most likely exists in
the unposted code.

The most usual cause of the Excel app not closing is an incorrect or
incomplete object reference. When using Automation it is critical to fully
qualify all your object references. If Access can't determine an Automation
ojbect reference, it will create another Excel Application object on its own
and use that. So when you Quit, you quit one, but not the other.

Check all your object references to be sure every object created refers all
the way back to the original Excel Application object.
--
Dave Hargis, Microsoft Access MVP


Martin said:
I have the following code in Access that is used to open an Excel file, do
some work with that file, then close the file and the Excel application.

Dim xlApp As Excel.Application
Set xlApp = CreateObject("Excel.Application")

xlApp.Workbooks.Open FileName:=HRFileName
With xlApp

[Work with the Excel file]


'Close HR File
.Workbooks(HRFile).Close False

End With

' Close Excel with the Quit method on the Application object.
xlApp.Quit
' Release the object variable.
Set xlApp = Nothing

Everything works fine except that after the script is completed, the Excel
application is open in the Windows Taskbar with the spreadsheet open in
Read-only mode.

Can someone offer some directioin as to how to stop this? It is annoying
for the end-user to have to close Excel after this script is done.

Thanks.
 
Back
Top