Interlop excel error Invoke code: Exception has been thrown by the target of an invocation

Hi Guys,

I was trying a Invoke code for excel read and write but on trying i am getting an error as
“RemoteException wrapping System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> RemoteException wrapping System.NullReferenceException: Object reference not set to an instance of an object.
at UiPathCodeRunner_eb2b3f30dcd24da781d6091be953b7c7.Run()”

below is the code for invoke code
"
Dim xl As Microsoft.Office.Interop.Excel.Application
Dim worksheet As Microsoft.Office.Interop.Excel.Worksheet
Dim workbook As Microsoft.Office.Interop.Excel.Workbook
Dim sheet As Microsoft.Office.Interop.Excel.Worksheet

workbook=xl.Workbooks.Open(“C:\Users\Sahanish\Desktop\Test1.xlsx”)

sheet=CType(workbook.Sheets(0),Microsoft.Office.Interop.Excel.Worksheet)
'sheet.Cells(1,1)=“This is done”

workbook.Save
workbook.Close
xl.Quit "

Any help will be highly appreciated…Thanks in advance…:slight_smile:

@ashok_n

As you said you are trying to read and write to excel

Instead of Invoke code, you can use the Excel activities to do the same

We need to use the Invoke Code when there is no activities available

Hope this helps

Thanks

Actually i want to insert a file in an excel cell…so i was trying with basic read and write interlop excel.but getting an error.:frowning: