Problems closing Excel correctly by code

F

Filips Benoit

Dear All,

W2000
Office2000

Access-application that manages quotations (= excel-files)

In a sub I change some values in an excel-file and close like this (see
code-end below)
.......
xlApp.Visible = False
........
Set WS = Nothing
WB.Close SaveChanges:=True
Set WB = Nothing
xlApp.Quit
Set xlApp = Nothing
Exit sub

This workes OK, BUT while re-opening this file or another I test if Excel is
running to prevent that several quotations are open at the same time.
Although there is no excel-file active the function IsExcelRunningNow()
returns TRUE

Where is the mistake?

THANKS³,

Filip

Function IsExcelRunningNow() As Boolean

Dim MyXL As Object ' Variable to hold reference to Microsoft Excel.
On Error Resume Next ' Defer error trapping.
IsExcelRunningNow = True
Set MyXL = GetObject(, "Excel.Application")
If Err.Number <> 0 Then IsExcelRunningNow = False
Err.Clear ' Clear Err object in case error occurred.
Set MyXL = Nothing ' Release reference to the application and
spreadsheet.

End Function
 
D

DM Unseen

Pls check if excel is running in the background invisibly.

Use MyXL.UserControl = false before you quit

BTW read up on the GetObject, since with excel allows the following:

Dim wb as Object

Set wb = Getobject("c:\Myfile.xls")

you could directly test if a quotation is open by connect to that
quotation.

Dm Unseen
 
F

Filips Benoit

Thanks,

BUT no change

Finally the problem was soved by changing my code ActiveSheet > WS

WS.Unprotect (varPassWord)
WS.Cells(2, 2) = "Basisofferte" & "=" & strBasisNaam
WS.Protect (varPassWord)

Thanks
 

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