Forum Discussion

windend's avatar
windend
Occasional Contributor
13 years ago

How to know sheet is not present in Excel workbook with DDT.ExcelDriver

hi, I'm using DDT.ExcelDriver to fetch data in excel like this :



excelDriver = DDT.ExcelDriver(excelPath,sheetName)



However, sometimes the sheetName is not present in my excel workbook, and above statement will be executed without any errors. Is there any way to judge whether my "excelDriver" is right in advance? which something likes:



if isNull(excelDriver) or excelDriver = nothing then

Log.Message(sheetName &"is not present in excel file"&excelPath)

end if



Or we can only know this by Error Numbers? Thank you.

4 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    How are you utilizing the ExcelDriver in that you don't know the sheet names that exist ahead of time?  The standard usage of the DDT objects is that they are used with files and/or databases that have a set of data that is predetermined prior to script execution.
  • windend's avatar
    windend
    Occasional Contributor
    yes, i can understand what does you mean. but sometimes the sheetname would be misspelled(we are planning to put the sheetnames and excelpaths in configure excel files to be related to different test cases). so i think the check is required.
  • ASV's avatar
    ASV
    Contributor
    Hi Amy



    I suggest you, if you need to know sheetname write in this way



    Set objExcel = Sys.OleObject("Excel.Application")


    objExcel.Workbooks.Open(strpathexcel)


    Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)



    If objSheet.Name = "the name that you want" then

    Log.Message("The sheetname is not exist")

    End if



    objExcel.DisplayAlerts = False


    objExcel.ActiveWorkbook.SaveAs(strPathExcel)


    objExcel.Workbooks.Close


    objExcel.Application.Quit


    Set objExcel = Nothing

  • windend's avatar
    windend
    Occasional Contributor
    Thank you,Vahagn. That's exactly what i use.