Forum Discussion

rhsou123's avatar
rhsou123
Contributor
8 years ago

Using Excel file with DDT driver in code

Hi,

This is my first Testcomplete script and I want to access to Excel file using DDT but I got this error message: " An Attempt to work with Closed Driver"

 

I verified my Excel, it is 32 bits and as what I said this my first connection.

 

This is my code:

 

In this script, I need to loop the sheet1 of the Excel file and verify if the value of the column "STP_Name" is different to "name1" and the value of the "Execute" column is "Y", if it is the case, display a message "Yeeeees".

 

Any help please, how can I solve this error ?

 

Sub execute()
set xlDriver = DDT.ExcelDriver("C:\Script-Resources\BatchRun\filename.xls","Sheet1",true)
xlDriver.First
Value1=xlDriver.Value("Execute")
Value2=xlDriver.Value("STP_NAME")
Value1=xlDriver.ColumnName(ColumnIndex)
Value2=xlDriver.ColumnName(ColumnIndex)
while not xlDriver.EOF
if value2 <> "name1" then
if Value1 = "Y" then 
BuiltIn.ShowMessage("Yeeeeeees")
else
BuiltIn.ShowMessage("Noooooooo")
end if
else 
BuiltIn.ShowMessage("Environment file")
end if
xlDriver.Next
wend
end sub
Sub Test1()
Call execute()
End sub

 

  • rhsou123's avatar
    rhsou123
    8 years ago

    Thank you !

     

    The problem is solved, I just tried with false instead of true and it works fine.

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    Do you have the Excel file open in Excel while you are attempting to run the code? If so, you will get the message you indicated.

    Something else a bit unrelated but will save you a headache later on, after your wend, you should call the following code

    Call DDT.CloseDriver(xlDriver.Name)

    A best practice is to always make sure you close your driver once you are done using it. It prevents a variety of problems later on.

    • rhsou123's avatar
      rhsou123
      Contributor

      Thank you !

       

      The problem is solved, I just tried with false instead of true and it works fine.

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        Ah, that could make a difference as well.  The "true" parameter for the ACE has to do, primarily, with which version of Excel you have installed. True is for versions of excel from Excel 2007 and newer. It has to do with which database driver you wish to use.

        Still, you really need to add the CloseDriver call to your code. If you don't, you may get a "max connections" error eventually.