killing an excel instance

  • Thread starter Thread starter meril_jacob
  • Start date Start date
M

meril_jacob

hi frens,

in the VB code i am working on, it opens an excel sheet from the cod
and i create a pivot table..........in the excel sheet, the proble
lies when even though i close the excel application using .quit th
excel instance is not getting closed.....should i close the pivot tabl
before closing the excel application if so how do i d
that??.........plz help me

Meri
 
Meril,

'------------------------------
Sub OpenInstanceOfExcel()
Dim appXL As Excel.Application
Dim WB As Excel.Workbook
Dim WS As Excel.Worksheet

Set appXL = New Excel.Application
Set WB = appXL.Workbooks.Add
Set WS = WB.Worksheets(1)

' Do your stuff with WS

Set WS = Nothing
WB.Close SaveChanges:=False 'Your choice
Set WB = Nothing
appXL.Quit
Set appXL = Nothing
End Sub
'------------------------------

It is very important that all references to Excel objects be qualified with the
proper parent reference, for instance...

Cells(10, 20) should be WS.Cells(10, 20)

Avoid use of "ActiveSheet" or "ActiveWorkbook" - use your object references.
Avoid the use of the "With" construct.

Regards,
Jim Cone
San Francisco, CA
 
Back
Top