ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Problems closing Excel correctly by code (https://www.excelbanter.com/excel-programming/333130-problems-closing-excel-correctly-code.html)

Filips Benoit

Problems closing Excel correctly by code
 
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



DM Unseen

Problems closing Excel correctly by code
 
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


Filips Benoit

Problems closing Excel correctly by code
 
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

"DM Unseen" wrote in message
oups.com...
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





All times are GMT +1. The time now is 02:42 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com