Forum Discussion

Vinod_Gulia's avatar
Vinod_Gulia
New Contributor
6 years ago

Compare Excel files - Object required: 'ExcelObj' (Run time error)

I've installed ExcelSheetCompare script extension and using the below mentioned code snippet taken from https://support.smartbear.com/viewarticle/9046/

 

Sub Main

Dim oExcel, aSheets, vSheet, fileName, aInfo1, aInfo2

 

 

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

Set aSheets = Sys.OleObject("Scripting.Dictionary")

 

 

'You can specify the sheet to be compared

vSheet = "Data"

Call aSheets.Add(vSheet, vSheet)

 

 

fileName = Project.Path + "\Data1.XLSX"

Set aInfo1 = ExcelObj.CreateInfo(oExcel, fileName, aSheets)

 

 

vSheet = "Data"

Call aSheets.Add(vSheet, vSheet)

 

 

 

fileName = Project.Path + "\Data2.XLSX"

Set aInfo2 = ExcelObj.CreateInfo(oExcel, fileName, aSheets)

 

oResult = ExcelObj.Compare(aInfo1, aInfo2)

If Len(oResult) > 0 Then

Log.Warning oResult

Else

Log.Message "The files are the same."

End If

 

oExcel.Quit

End Sub

 

 

I get the following error everytime I run my code: -

 

VBScript runtime error.

Object required: 'ExcelObj'

Error location:
Unit: "MAP Framework\Framework\Script\Excel"
Line: 105 Column: 3.

4 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    In that code, which line is generating the error?

    One thing I see potentially wrong (haven't tried it), you're adding the "Data" sheet to the aSheets dictionary twice.  Remove the second instance of 

     

    vSheet = "Data"
    
    Call aSheets.Add(vSheet, vSheet)

    and try again.

    • Vinod_Gulia's avatar
      Vinod_Gulia
      New Contributor

      Hi,

       

      Exception is thrown at following line of code: -

      Set aInfo1 = ExcelObj.CreateInfo(oExcel, fileName, aSheets)

       

      Call aSheets.Add(vSheet, vSheet) seems correct. Key as Object and Item as Object get added into Dictionary.

       

       

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        Right, it's correct... but you have it added twice.  Remove the second instance of the code to add to the aSheets.