Ask a Question

How to close Excel window cleanly

Yusufm87
Contributor

How to close Excel window cleanly

Hi, 

 

I need to close Excel application opened using TestApps["EXCEL"]["Run"] method.

I have tried closing the excel using the TestedApp["Close"]() method but it only closes the Excel window.

The "EXCEL.EXE" process keeps running in the background.

 

Could anyone show me how can I close Excel so that the background process also gets terminated just like how it works when we manually close an open Excel window.

 

I have used TestedApp["Terminate"](); method but it causes issues in further iterations where I need to wor on Excel.

 

 

Thanks,

Yusuf Malak

7 REPLIES 7
shankar_r
Community Hero

You can use Process.Terminate()

Ex: Sys.Process("EXCEL").Terminate()

 

By the way, why you are running Excel using TestedApps?  If you are doing this to grab values from excel then I would suggest you use DDT.ExcelDriver() method


Thanks
Shankar R

LinkedIn | CG-VAK Software | Bitbucket | shankarr.75@gmail.com

“You must expect great things from you, before you can do them”

Extension Available

Hi Shankar,

 

Thank you for you solution. But as I mentioned in my message that using ["Terminate"]() causes application to misbehave, I cannot use it under the circumstance.

In our test cases we are verifying various fields in Excel and checking if the formulas work. We are not retrieving any test data from excel.

 

 

Best Regards,

Yusuf

In order to check the formula, you have to retrieve the value from excel validate whether the value is being calculated correctly.

If this statement is true in your case then you can very well use DDT.ExcelDriver() to retrieve the value and verify


Thanks
Shankar R

LinkedIn | CG-VAK Software | Bitbucket | shankarr.75@gmail.com

“You must expect great things from you, before you can do them”

Extension Available

If not DDT then ADO might work better.

 

https://support.smartbear.com/testcomplete/docs/reference/program-objects/ado/index.html

 

Personally, I would not choose to open Excel just to read values from it.  DDT has capacities that would allow that, and if sufficient, ADO works great. 

hi,

my Excel-closing routine works as follows:

 

While Excel Process exists

   get visible "XLMAIN" Windows

   If #XLMAIN > 0 Then

      Set ExcelApp = Xlmainwindow.Window("XLDESK").Window("EXCEL7").NativeObject.Application.Application

      For Ix = ExcelApp.Workbooks.Count To 1 Step -1

         ' close Workbooks without saving

         If ExcelApp.Workbooks(Ix).Windows(1).Visible Then ExcelApp.Workbooks(Ix).Close False

      Next

      ExcelApp.Quit

      Set ExcelApp = Nothing

   End IF

End While

TanyaYatskovska
SmartBear Alumni (Retired)

Hi @Yusufm87,

 

Actually, it's quite strange that the Excel process exists after calling the TestedApp.Close method. What TestComplete version are you using? I suggest that you update to the latest product version and check if you see the same issue.

If you do, please contact our Support Team - some investigation should be done in our test lab:

http://support.smartbear.com/message/?prod=TestComplete

---------
Tanya Yatskovskaya
SmartBear Community and Education Manager



Hi Tanya,

 

We are using Test Complete Version: 12.42.3048.7 x64.

Kindly let us know if there are any fixes provided in the later versions for issues like this.

 

 

Thanks,

Yusuf

cancel
Showing results for 
Search instead for 
Did you mean: