Working on a requirement where I need to add tab in excel file

I am working on a requiremnet where the input file (Excel file comes in first time for the day)
and if the second file comes in a same day then need add a tab (Second run) in first input file

How can I achieve this automation ?

Thanks in advance !!
image

1 Like

@mittal.abhishek066

If only two then…if the file already exists then instead of using first run use the sheet name as second run in write range activity…with same filename…so it adds second

Cheers

1 Like

Hey there,
If you need to automatically add a tab to an Excel file when a second file comes in on the same day, you can use a tool like Python or Power Automate.

Hi @mittal.abhishek066
You can achieve this automation using the following steps:

  1. Use the “Excel Application Scope” activity to open the Excel file.
  2. Use the “Read Range” activity to read the data from the first sheet of the Excel file into a DataTable variable.
  3. Check if the Excel file already has a sheet named “Second run”. You can use the “Get Workbook Sheets” activity to get a list of all the sheets in the Excel file, and then use a “For Each” loop to iterate through the list and check if “Second run” exists.
  4. If “Second run” does not exist, use the “Add Data Row” activity to add a row to the DataTable variable that contains the name of the new sheet (“Second run”).
  5. Use the “Write Range” activity to write the DataTable variable back to the first sheet of the Excel file.
  6. If “Second run” already exists, you can skip step 4 and use the “Add Data Table” activity to add the contents of the second file to the existing sheet.
    Note: Make sure to close the Excel file after you are done with it using the “Close Workbook” activity.