I have an Excel file with multiple sheets named dd.MM.yyyy format. I want to use UiPath to arrange these sheets without using Excel Application Scope. Every day, new sheets are added, but instead of being arranged in order, they are placed after the last created sheet.
For example, i want the sheet “21.12.2023” to be after “20.12.2023”.
Using wb As New ClosedXML.Excel.XLWorkbook(filename)
Dim sheets As ClosedXML.Excel.IXLWorksheets = wb.Worksheets
Dim arrSheetName As String() = sheets.Select(Function(s) s.Name).OrderBy(Function(s) DateTime.ParseExact(s,"d.M.yyyy",System.Globalization.CultureInfo.InvariantCulture)).ToArray()
Dim i As int32 =1
For Each s As String In arrSheetName
wb.Worksheet(s).Position=i
i=i+1
Next
wb.Save()
End Using
Please note that this sample assumes all the sheetname is dd.MM.yyyy style.