Welcome to the OpenOffice Forum.
Calc spreadsheet documents contain sheets. When you create a new Calc spreadsheet it has 3 sheets whose names appear on the tabs along the bottom of the document. Internally Calc uses index numbers rather than names to refer to the sheets so originally
Sheet1 is assigned an index of 0, Sheet2 is 1 and
Sheet3 is 2. When more sheets are added they get the next available index number. Sheets also have names (Sheet1 etc.) and can be renamed, but they retain the index they were assigned when they were created. Each time the spreadsheet is opened the sheets are displayed in index order. Sometimes there can be quite a few sheets that have been renamed and it can be a little difficult to locate them by those names because they can appear in somewhat random order. The macro above sorts the sheets by name and reassigns the index numbers so that they will appear in alphabetical order.
The
BubbleSortList macro code is part of the Tools macro library supplied with Base.
You can look at the code by selecting
Tools>Macros>Organize Macros>OpenOffice Basic to open the
OpenOffice Basic Macros dialog (or use the shortcut key combination <Alt>F11).
In the left panel of the dialog navigate to
OpenOffice Macros>Tools>Strings.
BubbleSortList is towards the bottom of the list.
The Bubble sort (sometimes referred to Exchange Selection sorting) algorithm is easy to understand and relatively easy to implement. It works ok on short lists like the sheet names on a spreadsheet, but it is the least efficient method of sorting so you wouldn't want to use it on a list with thousands of records.
Cells too have indexes for so for instance
Code: Select all
oCell = oSheet.GetCellbyPosition( 0, 0 )
loads a cell object into the variable
oCell found in cell A1 (0,0) of a previously obtained sheet object
oSheet.
To actually see all the Properties and available Methods in the
oCell object an object inspection tool is indispensable.
[Tutorial] Introduction into object inspection with MRI
For more information see Chapter 15 of Andrew Pitonyak's book which is devoted to spreadsheets. He also has another document "Useful Macro Information" that contains a number of examples of Calc macros.
Programmed macros should be a last resort. Before you dive too deeply into macro programming, your time may be better spent leaning to use the built in spreadsheet options and functions because you can often accomplish your task without the brain damage of writing a macro.
Calc also has a
Macro Recorder (Tools>Macros>Record Macro) which can sometimes accomplish the task without programming.
As a point of etiquette, rather than tacking a question onto a thread that has been marked [Solved], it would be better to start a new thread with your question.
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11