Write Range Workbook: Object reference not set to an instance of an object


I’m getting the following error using the write range workbook, idk why !


Source: Write Range Workbook

Message: Object reference not set to an instance of an object.

Exception Type: System.NullReferenceException

System.NullReferenceException: Object reference not set to an instance of an object. at UiPath.Excel.Activities.WorkbookActivity`1.EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
at System.Activities.AsyncCodeActivity.System.Activities.IAsyncCodeActivity.FinishExecution(AsyncCodeActivityContext context, IAsyncResult result)
at System.Activities.AsyncCodeActivity.CompleteAsyncCodeActivityData.CompleteAsyncCodeActivityWorkItem.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)

The excel file has all the data needed, I have used before and never faced such issue…


Are you trying to access a non initialized var ?
This message happens when you are using a variable with Nothing

Are you using an existing workbook when you try to open this one ?

HI @MHarakeh

Can you check the DataTable variable is assigned correctly in the process?

Can you share the screenshot of your workflow?


Hi @Yamatendo @Gokul001

This is a screenshot

The ReadDT variable is declared as DataTable, nothing wrong here

The workbook path seems to wrong. Try reading the filename with log message to ensure it’s correct.

can you use output data table activity to check ReadDT has some values?

Then why do have the issue @MHarakeh ? Before write range activity take the dt count

Use message box and check it



I advise you to use a excel application scope and use the write range inside, there is two write range activity and the other one don’t need the path because it’s used in the scope.
If you’re stuck with no reason you can try to use this. I remember someone the tolds me to not use this write range, but i don’t have experienced problem myself so it’s just a supposition

Hi @mayur.pawanikar

When debugging the DataTable value is showing as Null.
ReadDT isn’t being passed there…
Although it’s declared

Yes, since the DataTable has null value, its not getting written into the Excel file.
Please check the activity where you are adding values to the ReadDT

Maybe you have declared two variables with the same name

Hi @MHarakeh

You can try with Try catch activity

In the catch block use Assign activity

ReadDT = New DataTable


Thanks Guys,

Figured it out I reused an excel scope activity and then the read range activity…

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.