Macro : Sorting sheets
A simple macro for sorting sheets in a spreadsheet in ascending alphabetical order.
Sub SortSheets
Dim oSheets
Dim oSheet
Dim i As Integer
Dim swap As Boolean
Dim oSheets
Dim oSheet
Dim i As Integer
Dim swap As Boolean
oSheets = ThisComponent.Sheets
If oSheets.getCount() > 1 Then ‘No sorting for one sheet
Do
swap = False ‘We continue bubble sort passes until no more swaps
For i = 0 to oSheets.getCount()-2
If oSheets.getByIndex(i).Name >
oSheets.getByIndex(i+1).Name Then
oSheets.moveByName(oSheets.getByIndex(i+1).Name,i)
swap = True
End If
Next
Loop Until swap = False
End If
End Sub