Adding and renaming excel sheet in a workbook

Hi,

I am having difficulties adding and renaming an excel sheet in a workbook, I went through some previous post referring to use hot keys activity, but that is not my mission. I like to use codes to solve the purpose.

workbookapplication.setSheet(sheetname as string, createnew as boolean)

I tried to use this code but did not get the success. Could someone help me to understand setSheet and getSheet method and is there any other method I should use to add and rename sheet?

Thanks.

1 Like

You can try Invoke VBA for executing the VBA code to rename the excel sheet.

Regards,
Karthik Byggari

1 Like

)Hi @raym174
Welcome to uipath community

— Fine to create a new sheet in excel a simple workaround is we can use use excel application scope activity and pass the file paste of the excel as input
— within this scope use a simple write cell or write range activity with the sheetname you want… with double quotes and it will create a new sheet in that excel

Then

To rename a excel kindly have a view on this thread once that could help you resolve this
[Excel renaming - #3 by ClaytonM](Excel renaming - #3 by ClaytonM

Cheers

1 Like

Thank you so much for the tips, these are two simple ways I can understand, but only to change a sheet name is it justified to invoke VBA?

Can you please help me to understand two methods “setSheet” and “getSheet” and uses?

@raym174

Please refer this BalaReva.Excel.Activities

You can install the balareva.excel.activities

If you want to rename your excel sheet

Thanks,
Aman sheik

2 Likes

Invoke VBA is actually easier than you think. When it is inside an Excel Scope, it interacts with the window, so it’s just a matter of using the VB for changing the sheet name.

I made a simple example:


where “July 2019” is the sheet you want to change and “New Name” is the new name which both in the parameters can be variables

image
and that is the script file created in Notepad using .vbs extension.

I also looked some of it on google to find the syntax for referencing a sheet name in vbscript code

Since those are actions, you can try using the Invoke Method but I’m not familiar with getting those working in UiPath.

To rename the sheet as linked by @Palaniyappan, I normally use an alt-key combo, which performs the Rename Sheet feature from the ribbon menu.
image
So the keystroke combo is Alt, h, o, r, “New Name”, enter
image

If I see anything on using SetSheets, I’ll let you know.

Regards.

3 Likes

To do the rename sheet can use this package …

Sample :

Regards
Balamurugan.S