i have a requirement where i have excel which as multiple sheet based on i have to pickspecific sheet name and then update data base issues is that even if sheetname has extra space or uppercase gives an error saying sheet not found
Hi @Navya Vani ,
You can use ToLower() and Trim() to make the worksheet-name comparison more flexible:
Before calling Worksheet_SelectByName, use Workbook_GetProperties to retrieve the properties and names of all worksheets in the workbook. Then use ListIndex to search for the required worksheet using ToLower() and Trim(). Example:
ToLower(Trim(WorksheetList.Current.Name)) = ToLower(Trim(ExpectedSheetName))
If ListIndex.Position = -1, the worksheet was not found. You can stop the flow and display an error.
If it is found, retrieve the original worksheet name using the returned position:
WorksheetList[ListIndex.Position].Name
Pass this value to Worksheet_SelectByName.
how to get all sheet names...??wht if user gives extraspace after sheetname
You can use Workbook_GetProperties action to get all sheet names. You can use Trim() to remove extra spaces before and after the sheet name.
You can follow the approach Mihai mentioned. If you need a working solution, please share the OML file.
@Navya Vani
The problem is that Worksheet_Select_ByName (and similar activities) do an exact string match against sheet names, so "Sheet1 " or "SHEET1" won't match "Sheet1".
Fix: don't pass the raw name straight in — get the workbook's actual sheet names first, then find the matching one using a trimmed/case-insensitive comparison.
Steps:
matchedSheet = allSheets.Where(Function(s) s.Trim().ToUpper() = inputSheetName.Trim().ToUpper()).FirstOrDefault()
This way, whatever casing/spacing the user typed, you always feed the activity the exact string Excel actually has, so it stops failing on trivial formatting differences.
If your activity set doesn't expose "get all sheet names" directly, you can get it via the Workbook_Open output object (its Sheets/SheetNames property) — check what's on your Workbook_Open result variable, since most Excel activity packages expose this.