Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unable to "Quit" excel while in VB mode

Status
Not open for further replies.

cassidybklyn

Programmer
Apr 23, 2007
82
US
I am trying to quit excel after processing. Below is what I am doing:

dim xlApp As Object
dim xlWb As Object
dim xlWksht As Object

Set xlApp = CreateObject("Excel.Application")
Set xlWb = xlApp.Workbooks.Add
Set xlWksht = xlWb.Worksheets("Sheet1")

process - process- process
"" "" ""

Set xlApp = Nothing
Set xlWb = Nothing
Set xlWksht = Nothing
xlApp.Quit <====================
xlApp.Application.Quit <========

Any of the last two lines of codes: "xlApp.Quit" or "xlAppl.Application.Quit" gives me Runtime error "91" (Object variable or With block variable not set)

How can I fix this?
Thanks.
C.

 
The culprit is here:
Set xlApp = Nothing

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
In other words...put the Quit before the Nothing.

How can you have something do an instruction (Quit), when you have set it to Nothing? Once set to Nothing...the "Object variable not set".

Use Nothing when there is...nothing left to do.

Gerry
My paintings and sculpture
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top