Write Cell: Index was outside the bounds of the array

I am trying to write variables (string) into a few cells in an excel spreadsheet with the Write Cell activity. Each time I get the following error: Index was outside the bounds of the array.

Can you share the input and a snippet of the code.

If array length is 5 i.e. a= {1,2,3,4,5} you can only till a(4) as the index would start with 0. If you try to print a(5), you would get outside of boundary error. Plz check if that is the case.

1 Like

I am not using any arrays. Please see code included:
The spreadsheet that will cause the error has 4 tabs. Simply looking to update the highlighted cell on the “Cover” sheet. The code will work for a very simple (blank) spreadsheet.

Here is the spreadsheet example:

Is it possible for you to provide this spreadsheet in attachment to see what exactly is happening ?

Test Sheet.xlsx (52.8 KB)

Hi @BoomBot,

I have tried to update value on cell AL1 and it’s working fine for me.
Is there any other cell you want to update value?

Thank you for the suggestion. I had tried to tried to write to the cell within the Excel application scope but get the following error even though excel is closed and nothing showing it is active in task manager.

Are you accessing it from shared drive?
Seems from error message it is opened somewhere.

Try to copy file to local and update cell value to it, this is just to check that the issue is occurring on shared drive only or on local also.

Try to use kill activity to kill excel before excel application scope.

And Last way to do it is from invoke code or macro.

I’ve tried changing the location of the file to my local C:\ drive and added the kill activity but the same error occurs. When you suggest a macro, would that be within excel or is it in UiPath?

I can create both, which one you prefer invoke code or macro.

I would prefer the code in UiPath since my plans would be to update multiple excel files in several folders and would be difficult to set up the macro in each one of those files.

WriteCell.xaml (5.3 KB)

Hope this will work for you.

1 Like

Hi @BoomBot ,

Is it worked for you ?

Unfortunately I have not been able to try it due to the errors. Please see attached.

you can add namespace microsoft.office.interlop to fix the issue


Just add package shown below

Package added and it worked!! Thanks so much for your help but also showing me some of the new options for programming in UiPath. Very exciting.

1 Like

Finally we did it @BoomBot :grinning:

1 Like