
Creating names in a workbook
createName-methods.RdCreates a named range for a specified formula in a workbook.
Arguments
- object
The
workbookto use- name
The name of the range to be created
- formula
Excel formula specifying the value / data the name refers to
- overwrite
If a name with the same
namealready exists andoverwrite = TRUE, then this name is removed first before the new one is created. If a name already exists andoverwrite = FALSE, then an exception is thrown. The default value foroverwriteisFALSE.- worksheetScope
Optional - specific worksheet the name should be scoped to. If unspecified the name will be scoped to the whole workbook.
Details
Creates a named range called name for the specified formula.
The formula should be specified as you would type it
in Excel. Make sure that the worksheets, functions, ...
exist that you are referring to in the formula.
The name, formula and overwrite arguments are
vectorized such that multiple names can be created in one method call.
References
What are named regions/ranges?
https://web.archive.org/web/20240821110221/https://www.officearticles.com/excel/named_ranges_in_microsoft_excel.htm
How to create named regions/ranges?
https://www.youtube.com/watch?v=iAE9a0uRtpM
Author
Martin Studer
Mirai Solutions GmbH https://mirai-solutions.ch
Examples
if (FALSE) { # \dontrun{
# Load workbook (create if not existing)
wb <- loadWorkbook("createName.xlsx", create = TRUE)
# Create a worksheet named 'mtcars'
createSheet(wb, name = "mtcars")
# Create a named region called 'mtcars' on the sheet called 'mtcars'
createName(wb, name = "mtcars", formula = "mtcars!$A$1")
# Write built-in data set 'mtcars' to the above defined named region
writeNamedRegion(wb, mtcars, name = "mtcars")
# Save workbook
saveWorkbook(wb)
# clean up
file.remove("createName.xlsx")
} # }