Hi,
I need to delete excel sheets dynamically means I need to pass the sheet name to delete.
Delete sheet - not working
used vba code - i think mcro blocked
is any other way ??
TIA
Hi,
I need to delete excel sheets dynamically means I need to pass the sheet name to delete.
Delete sheet - not working
used vba code - i think mcro blocked
is any other way ??
TIA
vbaCopy code
Sub DeleteSheetByName(sheetName As String)
On Error Resume Next
ThisWorkbook.Sheets(sheetName).Delete
End Sub
Please check this post.
Thanks for reply @copy_writes
As i already mentioned i used invoke VBA but macros are blocked I am unable to use VBA hence looking for other solution.
Delete sheet activity also not working?
If macros are blocked, and the âDelete Sheetâ activity in UiPath is not working for your specific use case, you can use the following alternative approach to delete an Excel sheet:
Use PowerShell Script:
You can leverage PowerShell to interact with Excel and delete specific sheets. Hereâs a step-by-step guide:
a. Use an âInvoke PowerShellâ activity in UiPath to run a PowerShell script.
b. In the PowerShell script, use the Remove-Item
cmdlet to delete the sheet file. You need to specify the Excel fileâs path and the name of the sheet to delete. Hereâs an example PowerShell script:
$excelFilePath = "C:\Path\to\YourExcelFile.xlsx"
$sheetNameToDelete = "SheetName"
$excel = New-Object -ComObject Excel.Application
$workbook = $excel.Workbooks.Open($excelFilePath)
# Find and delete the sheet
foreach ($worksheet in $workbook.Sheets) {
if ($worksheet.Name -eq $sheetNameToDelete) {
$worksheet.Delete()
break
}
}
$workbook.Save()
$workbook.Close()
$excel.Quit()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($excel)
Make sure to replace the paths and sheet name with your specific details.
c. In the UiPath âInvoke PowerShellâ activity, pass the PowerShell script as an argument.
This approach uses PowerShell to manipulate the Excel file and delete the specific sheet without relying on macros or the âDelete Sheetâ activity in UiPath. Ensure that your system has PowerShell enabled, and you have the necessary permissions to modify the Excel file.
@copy_writes
delete sheet gives error when I am giving excel sheet name there
error
option strict on disallows implicit conversions from âstringâ to âUiPath.Excel.ISheetRefâ
here , how to pass sheet name dynamically ?
Can you try this expression Delete sheet activity Excel.Sheet(StrSheetName)
You can pass the your sheet name in string variable StrSheetName = âSheet1â
Refer the screenshot
Regards
Gowtham.K
The error youâre encountering, âOption Strict On disallows implicit conversions from âstringâ to âUiPath.Excel.ISheetRefâ,â is because the âDelete Sheetâ activity in UiPath expects an object of type ISheetRef
, not a simple string containing the sheet name. This error is related to strong typing and data type compatibility in UiPath.
@Gowtham_krishnan
Thanks for ur reply !
I am using classic activities so, I am not getting reference as option and.
If I used above expression , getting error Excel is not declare
@8b6861dc5e0c9f7008548ca66 share workflow screenshot
You can use modern activity
@Gowtham_krishnan
Apologies!
Itâs working Need to used within excel process scope and then Use excel file . I was using Excel app scope .
Thanks a lot !!
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.