Select the range containing the headers and the data and then use Insert > Names
> Create to open the Create Names dialog (see Figure 322), which allows you to
simultaneously create multiple named ranges based on the top row, bottom row, right
column or left column. If you choose to create ranges based on the top row, one
named range is created for each column header—the header is not included in the
named range. Although the header is not included in the range, the text in the header
is used to name the range.
Figure 322. 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.
318 OpenOffice.org 3.3 Calc Guide
Komentáře k této Příručce