Forum Discussion

guna's avatar
guna
New Contributor
3 years ago

object required error

Hi all,

 I am upgrading from 14 to 15 version recently. I am unable to get it this one, some times the code is executing successfully and sometimes getting Object required error, below one is the code

 

Dim TestReportFolder ,Test_reportexcel ,FinalTest_reportexcel

Function GetRecentExcel_InsertData

Set fso = CreateObject("Scripting.FileSystemObject")
Set recentExcel = Nothing
For Each file in fso.GetFolder(Test_Report_Path).Files
If (recentExcel is Nothing) Then
Set recentExcel = file
ElseIf (file.DateLastModified > recentExcel.DateLastModified) Then
Set recentExcel = file
End If
Next

If recentExcel is Nothing Then
log.Message( "No recent Test Report")
Else

Test_reportexcel = recentExcel.Name
log.Message(Test_reportexcel)

End If


aqUtils.Delay 1000
aqUtils.Delay 2000
Set app = Sys.OleObject("Excel.Application")
TestReportFolder = Test_Report_Path
FinalTest_reportexcel = TestReportFolder + "\" + Test_reportexcel
log.Message(FinalTest_reportexcel)
Set TestReportWorkBook =app.Workbooks.Open(FinalTest_reportexcel) --->at this line i am getting object required error

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    My VBScript is not very good, but I'm able to write the following code to launch and open the Excel file

     

    Sub Test1()
        Dim Excel, Filename
        Filename = "C:\Temp\Book1.xlsm"
        Set Excel = Sys.OleObject("Excel.Application")
        Excel.Visible = True
        Excel.Workbooks.Open(Filename)
        Excel.Quit
    End Sub

     

    Ensure you have Excel installed, and that the user has correct permissions. Also, ensure that the filename follows the Universal Naming Convention, i.e. "C:\Temp\Book1.xlsm" is different to this "C:\\Temp\\Book1.xlsm"