Delete sheets with dynamic names from excel UiPath
A lot of times while working with excels there will be a scenario where we need to delete sheets with dynamic names or static sheet names from excel.
In this article let’s see how we can delete sheets with dynamic names or static sheet names from excel using UiPath.
In this example, we are going to look at two scenarios:
- Sheet with static name
- Sheet with dynamic name
Let’s get into the practical implementation of this task:
Step1: Firstly we are going to see how to delete a static sheet name excel and in this example, we have two sheets those are Sheet1 and Sheet2.
Step2: Drag and Drop excel application scope from activities panel to designer panel as shown below:
The parameters remain the same but if you want to check them click here.
Step2: Drag and Drop Invoke VBA activity from activities panel to designer panel as shown below:
There is no need for any property change in Invoke VBA activity here.
Step3: Open a text file and write the code inside it as shown below:
Sub Deletesheet()
Sheets("Sheet2").Delete
End Sub
This will delete the sheet with the name Sheet2.
Now let’s see how to pass this sheet name dynamically to Invoke VBA activity.
Step1: Drag and Drop excel application scope and Invoke VBA activity from activities panel to designer panel as shown below:
The below image shows the required properties for invoke VBA activity to pass the sheet name dynamically:
Here:
- CodeFilePath – Pass the file path where you saved the VBA code.
- EntryMethodName – Pass the same method name that is used in VBA code.
- EntryMethodParameters – Pass the sheet name here as shown above that will be taken as input sheet name for VBA code.
Step2: Change the code in the text file which is passed as input to Invoke VBA activity as shown below:
Sub Deletesheet(sheetName)
Sheets(sheetName).Delete
End Sub
Where sheetName is the entry method parameter that takes the provided sheet name from the Invoke VBA activity.
This is how we can delete sheets with dynamic names from excel.