problem closing excel

B

Bre-x

Hi,
I have this function that allows me to check if a sheet exits on a specific
workbook. It works fine but i have a problem closing ms excel
It still running on my Windows Tasks Manager.

Thank you all.
Bre-x


Function WorksheetExist(TF As String) As Boolean
Dim objXL As Object
TheFile = TF
Set objXL = CreateObject("Excel.Application")
With objXL.Application
.Visible = False
.Workbooks.Open TheFile
Dim ws, wsName
wsName = "Main"
For Each ws In .Worksheets
If UCase(ws.Name) = UCase(wsName) Then
WorksheetExist = True
.Workbooks.Close
.Quit
Exit Function
End If
Next
WorksheetExist = False
.Workbooks.Close
.Quit
End With
Set objSht = Nothing
Set objXL = Nothing
End Function
 
J

Jim Rech

I'm not sure if it will help but you are not setting the objects to nothing
when the sheet exists.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top