REM Select the range to sort.
REM The only purpose would be to emphasize the sorted data.
'ThisComponent.getCurrentController.select(oCellRange)
REM The columns are numbered starting with 0, so
REM column A is 0, column B is 1, etc.
REM Sort column B (column 1) descending.
oSortFields(0).Field = 1
oSortFields(0).SortAscending = FALSE
REM If column B has two cells with the same value,
REM then use column A ascending to decide the order.
oSortFields(1).Field = 0
oSortFields(1).SortAscending = True
REM Setup the sort descriptor.
oSortDesc(0).Name = "SortFields"
oSortDesc(0).Value = oSortFields()
REM Sort the range.
oCellRange.Sort(oSortDesc())
End Sub
As this macro is a subroutine, you execute it with Tools > Macros > Run Macro
and then open CalcTestMacros > AuthorsCalcMacros > Module1. Click on the
macro SortRange and then Run.
Conclusion
This chapter provides a brief overview on how to create libraries and modules, using
the macro recorder, using macros as Calc functions, and writing your own macros
without the macro recorder. Each topic deserves at least one chapter, and writing
your own macros for Calc could easily fill an entire book. In other words, this is just
the beginning of what you can learn!
312 OpenOffice.org 3.3 Calc Guide
Comentarios a estos manuales