Ask a Question

How to Use Excel file with DDT driver in code ,without opening the excel file

Nitish
Occasional Contributor

How to Use Excel file with DDT driver in code ,without opening the excel file

When I try to access excel with DDT driver ,with Excel file open ,code is working fine , but as soon as I run code the with excel file closed ."An attempt to work with closed driver ".Is there any workArround that I can use to run the code without opening the excel file  

10 REPLIES 10
Ryan_Moran
Valued Contributor

Re: How to Use Excel file with DDT driver in code ,without opening the excel file

Can you post a snippet of your code so we can see exactly how you are using the driver?


''-Praise the sun and Give Kudos.''
Nitish
Occasional Contributor

Re: How to Use Excel file with DDT driver in code ,without opening the excel file

FileName = "Path of the file "
intCount = 0
'set Objdriver = DDT.ExcelDriver(FileName , SheetName)
set objdriver = DDT.ExcelDriver(FileName ,SheetName,)

' do While not(objdriver.EOF())
' intCount = intCount+1
' objdriver.Next()
' loop

While not(objdriver.EOF())
intCount = intCount+1
objdriver.Next()
Wend
DDT.CloseDriver(objdriver.Name)
redim arrInput(intRecCount)
set objdriver = DDT.ExcelDriver(FileName , SheetName,true)


for LoopCount = 0 to intRecCount-1
if IsNull(DDT.CurrentDriver.Value(intColumnNo)) then
ArraySize = LoopCount - 1
exit For
Else
arrInput(LoopCount) = VarToStr(DDT.CurrentDriver.Value(intColumnNo))
objdriver.Next()
ArraySize = intRecCount
end if
next

DDT.CloseDriver(objdriver.Name)
redim arrdata(ArraySize)

for LoopCount1 = 0 to UBound(arrdata)
arrdata(LoopCount1) = arrInput(LoopCount1)
next

ReadExcel = arrdata

End Function

Nitish
Occasional Contributor

Re: How to Use Excel file with DDT driver in code ,without opening the excel file

 
Marsha_R
Community Hero

Re: How to Use Excel file with DDT driver in code ,without opening the excel file

Where in the code does the error show up?


Marsha_R
[Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
Nitish
Occasional Contributor

Re: How to Use Excel file with DDT driver in code ,without opening the excel file

FileName = "Path of the file "
intCount = 0
'set Objdriver = DDT.ExcelDriver(FileName , SheetName)
set objdriver = DDT.ExcelDriver(FileName ,SheetName,)//here it shows

' do While not(objdriver.EOF())//here it shows 
' intCount = intCount+1
' objdriver.Next()
' loop

While not(objdriver.EOF())

Ryan_Moran
Valued Contributor

Re: How to Use Excel file with DDT driver in code ,without opening the excel file

 

Try this:

FileName = "Path of the file "
intCount = 0
'set Objdriver = DDT.ExcelDriver(FileName , SheetName)
Set objdriver = DDT.ExcelDriver(FileName ,SheetName)

' do While not(objdriver.EOF())
' intCount = intCount+1
' objdriver.Next()
' loop

While not(objdriver.EOF())
  intCount = intCount+1
  objdriver.Next()
Wend
DDT.CloseDriver(objdriver.Name)
redim arrInput(intRecCount)
Set objdriver = DDT.ExcelDriver(FileName ,SheetName)

For LoopCount = 0 To intRecCount-1
  if IsNull(DDT.CurrentDriver.Value(intColumnNo)) then
    ArraySize = LoopCount - 1
    exit For
  Else
    arrInput(LoopCount) = VarToStr(DDT.CurrentDriver.Value(intColumnNo))
    objdriver.Next()
    ArraySize = intRecCount
  End If
Next

DDT.CloseDriver(objdriver.Name)
redim arrdata(ArraySize)

For LoopCount1 = 0 To UBound(arrdata)
  arrdata(LoopCount1) = arrInput(LoopCount1)
Next
ReadExcel = arrdata

End Function

''-Praise the sun and Give Kudos.''
Nitish
Occasional Contributor

Re: How to Use Excel file with DDT driver in code ,without opening the excel file

Thankyou ryan for Replying 
but the above code is throwing the same error .
An attempt to work with closed driver.

Colin_McCrae
Community Hero

Re: How to Use Excel file with DDT driver in code ,without opening the excel file

Not sure if yours is the same problem, but this was raised, and solved, on here before:

 

https://community.smartbear.com/t5/Functional-Web-Testing/An-Attempt-to-work-with-Closed-Driver-in-T...

 

Was down to trying to open too many connections .....

 

And also here:

 

https://community.smartbear.com/t5/Desktop-Testing/TC11-DDT-An-attempt-to-work-with-a-closed-driver/...

 

Where it was down to drivers.

Ryan_Moran
Valued Contributor

Re: How to Use Excel file with DDT driver in code ,without opening the excel file

If this is the case then reboot your PC and try again.

If it works for a period of time after rebooting then you have an issue with the driver not being closed properly.


''-Praise the sun and Give Kudos.''
cancel
Showing results for 
Search instead for 
Did you mean: