Macros/Calc/ba022

Summary
This page provides a LibreOffice Basic macro procedure that creates a new database range referencing $Sheet1.$A$1:$F$10. It is an example drawn from Chapter 13 ("Calc as a Database") of the 7.0 Calc Guide.

Description
In a macro, a database range is created, accessed, and deleted using the DatabaseRanges service. This service has many of the same methods as the NamedRanges service, but lacks the addNewFromTitles method. DatabaseRanges also uses a reduced version of the addNewByName method that lacks arguments for a relative base address and range type :
 * addNewByName( Name, Range )
 * Adds a new database range to the current document.

As an example of creating a range using this method, the macro below creates a database range named MyName and automatically applies auto filters to each of the range’s columns:

Code
This [[Media:Create_database_range_with_macro.ods|Calc spreadsheet]] contains the above LibreOffice Basic code.