troubleshooting Question

closing Excel.exe

Avatar of developingprogrammer
developingprogrammer asked on
Microsoft Excel
12 Comments1 Solution316 ViewsLast Modified:
hey guys,

i had a problem with closing excel.exe and i found the solution myself through testing, but i don't understand why it's happening.

here's what i did - perhaps yall could explain to me the why = )


    Set xlsApp = New Excel.Application
    With xlsApp
        .Visible = False
        Set xlsWbk = .Workbooks.Open(strPathOfSourceFile, , True)
    End With

    Set xlsWst = xlsWbk.Worksheets(strWorksheetName)

    Set rngLimitsTestCell = xlsWst.Cells(1, 1)

now i want to close the Excel.exe process that was created

so here is what works and what doesn't

this works

    Set rngLimitsTestCell = Nothing
    Set xlsWst = Nothing
    xlsApp.DisplayAlerts = False
        xlsApp.Quit
    xlsApp.DisplayAlerts = True
    Set xlsApp = Nothing

this does not work
xlsApp.DisplayAlerts = False
        xlsApp.Quit
    xlsApp.DisplayAlerts = True
    Set xlsApp = Nothing

why must i
Set rngLimitsTestCell = Nothing
and
Set xlsWst = Nothing
first?

what i think is that in the hierarchy tree, xlsApp-->xlsWbk-->xlsWst-->rngLimitsTestCell
so if i
    xlsApp.DisplayAlerts = False
        xlsApp.Quit
    xlsApp.DisplayAlerts = True
    Set xlsApp = Nothing

that closes the Excel application without saving and then sets xlsApp to nothing. this should cascade down and thus the Excel.exe should also close right?

note i don't need to Set xlsWbk = Nothing.

this leads me to think that i need to set all grandchildren objects to nothing but for children objects the nothing state is automatically cascaded down.

perhaps guys yall can correct my way of thinking? thanks guys!! = ))
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 12 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 12 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros