Forum Discussion

xuerzj's avatar
xuerzj
New Contributor
9 years ago

Is there a way to close all open excel drivers?

Sometimes the test is failed and then stopped before closing the excel driver. Then it starts to run the next test. The next test also creats a driver with same name, as a result it uses wrong excel file which is for the previous test. 

 

How should I handle this situation? Is there a way to check if there are open excel drivers and close them? I may need to put the check in Event Handler onlogerror. 

 

Thank you.

7 Replies

  • Ravik's avatar
    Ravik
    Super Contributor
    Hi, First you have to check in your Test is there any process is running for excel, If its running close it. Do one thinng - Add Excel process in Name Mapping and check like below - Sub CloseExcel Set objExcelKill = NameMapping.Sys.EXCEL Do while objExcelKill.Exists = True objExcelKill.Terminate Loop Set objExcel = CreateObject("Excel.Application") objExcel.DisplayAlerts = False objExcel.Visible = True End Sub This may help you.
  • Ravik's avatar
    Ravik
    Super Contributor
    Hi, First you have to check in your Test is there any process is running for excel, If its running close it. Do one thinng - Add Excel process in Name Mapping and check like below - Sub CloseExcel Set objExcelKill = NameMapping.Sys.EXCEL Do while objExcelKill.Exists = True objExcelKill.Terminate Loop Set objExcel = CreateObject("Excel.Application") objExcel.DisplayAlerts = False objExcel.Visible = True End Sub This may help you.
    • xuerzj's avatar
      xuerzj
      New Contributor

      Thanks for your input. 

       

      It is not working for me. When a excel driver is created, the excel object does not exist. 

       

      Any suggestion? Thank you.

      • leandroaraujoso's avatar
        leandroaraujoso
        Contributor

        Hi xuerzj,

         

        You could create an OnStopTest event. In this event you would check weather or not exists an open Excel connection and then close it.

         

        Regards,

         

        Leandro de Araújo Souza