Calc Guide

Figure 305. Define a named range.
The macro in Listing 12 creates three named ranges based on the top
row of a named range.
Listing 12. Create many named ranges.
Sub AddManyNamedRanges()
Dim oSheet 'Sheet that contains the named range.
Dim oAddress 'Range address.
Dim oRanges 'The NamedRanges property.
Dim oRange 'Single cell range.
oRanges = ThisComponent.NamedRanges
oSheet = ThisComponent.getSheets().getByIndex(0)
oRange = oSheet.getCellRangeByName("A1:C20")
oAddress = oRange.getRangeAddress()
oRanges.addNewFromTitles(oAddress, _
com.sun.star.sheet.Border.TOP)
End Sub
The constants in Table 14 determine the location of the headers when
multiple ranges are created using the method addNewFromTitles().
Table 14. com.sun.star.sheet.Border constants.
Value Name Description
0 TOP Select the top border.
1 BOTTOM Select the bottom border.
2 RIGHT Select the right border.
3 LEFT Select the left border.
Caution
It is possible to create multiple named ranges with the same
name. Creating multiple ranges with a single command
increases the likelihood that multiple ranges will be created
with the same name—avoid this if possible.
Chapter 13 Calc as a Simple Database 363