Writing to a new "sheet" in Excel Workbook

I run a bot once a day that collects invoice data to be written to an Excel Workbook. Currently, I have set up a “template” sheet that includes all the headers I will need. Everytime I run my process, I want a to duplicate the template sheet and rename the copy with the current date using Date.now. I have gotten that far successfully.

My issue is not knowing how to I get my data variables written to the current sheet since the write cell activity wants an explicit target. I don’t really need to use a for each excel row do I?


Hi @chris.bartkewicz

Where do you have data saved that you want to write in the new sheet?

Do you have it in datatable? or separate variables?

if you have in a datatable, you can simply use write range activity to write the data from range “A2”.

all my data is individual variables (substrings from unique PDFs)

In that case, instead of writing to excel cell by cell.

I would suggest to build a datatable by assigning your variables to data rows.

Once, done, write range datatable to excel at once

Great suggestion. As I build each table to represent a single “sheet” in the workbook, can I still add each new sheet when I run. Remember, I need to add a sheet everytime I run the bot to ensure I dont rewrite over previous days entries.

Yes, in your write range, you can specify the date so everyday when you run the process, a new sheet will be created with the date. Or you can give some other name you want.

If you want to provide date as name, please follow my comment in other topic you had raised on somewhat similar query.

Thank you for the continued help. I took your suggestion and build a date table and Studio and then use "write Datatable to excel to get the data into the workbook, but I am still faced with the same issue - I cannot get each run to write to the new sheet because you cannot write a new sheet in as a variable. UiPath only recognizes my current template sheet since it is technically the only tangible sheet in the workbook before running.

Hi @chris.bartkewicz

I see you are already creating a new sheet using duplicate sheet command.

if you are creating your sheet like this, then you only need to write range in the same sheet that was created.

Do below:

1)In your duplicate sheet activity, under rename to property, provide a sheet variable name instead.
2)before duplicate activity, assign sheet variable the same value that you have right now like Date.Now…
3) then use the same variable under duplicate sheet
4) use same variable name under write range.

It should work

So what I did was just hold off on the name of the sheet and duplicated the “template” sheet so that I can grab my headers. My data table then writes to my duplicate sheet with formatting and headers titled “new sheet”.

So I have my data on a new sheet, but now this is where I am now trying to rename the sheet retroactively to the current datetime. But I am having some declaring issues.


@chris.bartkewicz

Can you select custom input under From and try

You have to provide like below:

Excel.Sheet(“New Sheet”) under From

Silly me, I totally forgot that syntax. Thanks for the help!

1 Like

@chris.bartkewicz

I am glad I could help!

If your query is now resolved, i would suggest to kindly mark my post as solution so this topic can be closed and help others as well.

Thanks.

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