End Excel in memory

A

Akilah

Hi, I have code that opens an Excel spreadsheet, does a process, then quits
Excel. Is there a way to close only that instance of Excel in memory so that
if I have other Excel spreadsheets open, they will stay open? Thanks.
 
V

vbasean

are you closing excel or setting the variable reference to excel to
nothing

ie.

Application.Close

or

set [your excel application variable] = Nothing
 
D

Dale Fye

How are you opening the Excel spreadsheet?

The following would open excel, open a workbook, do something, save the
workbook, close it, then, depending on whether Excel was open when you opened
your workbook, it would either leave Excel Open, or Quit. Instead of testing
whether Excel was open when you opened your workbook, you might just want to
check to see whether there are any other workbooks open, and if so, leave
Excel open. (air code, so may require tweaking)

Private Sub OpenExcel

Dim bExcelWasOpen as boolean
Dim xlApp as Excel.Application
Dim wbk as Excel.Workbook

On Error Resume Next
Set xlApp = GetObject(, "Excel.Application")
If Err.Number = 0 then
bExcelWasOpen = True
Else
bExcelWasOpen = False
Set xlApp = CreateObject("Excel.Application")
End if
xlapp.visible = true
Set wbk = xlApp.Workbooks.Open(Filename:=Filename, ReadOnly:=False)
.... Do something here

wbk.save
wbk.close
If bExcelWasOpen = False then xlApp.Quit

End Sub
 
K

Ken Snell \(MVP\)

This problem usually results from the use of a not fully qualified reference
to an object in the EXCEL application. If you post your VBA code, we likely
can point it out to you.

See this Microsoft Knowledge Base article for more information about this
"phenomenon" (see the topics "The Problems in Using Unqualified Code with
Office" and "Qualifying the Code to Avoid Errors"):
INFO: Error or Unexpected Behavior with Office Automation When You
Use Early Binding in Visual Basic
http://support.microsoft.com/kb/319832/
 
Top