Forum Discussion

Nitish's avatar
Nitish
Occasional Contributor
8 years ago

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

    • Nitish's avatar
      Nitish
      Occasional Contributor

      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's avatar
    Ryan_Moran
    Valued Contributor

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

  • Nitish's avatar
    Nitish
    Occasional Contributor

    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

    • Ryan_Moran's avatar
      Ryan_Moran
      Valued Contributor

       

      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
      • Nitish's avatar
        Nitish
        Occasional Contributor

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