Forum Discussion
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
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- Nitish10 years agoOccasional Contributor
Thankyou ryan for Replying
but the above code is throwing the same error .
An attempt to work with closed driver.- Colin_McCrae10 years agoCommunity Hero
Not sure if yours is the same problem, but this was raised, and solved, on here before:
Was down to trying to open too many connections .....
And also here:
Where it was down to drivers.
- Ryan_Moran10 years agoValued Contributor
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.