Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Cmdlet

Rename-OfficeExcelNamedRange

Module
PSWriteOffice
Inputs
OfficeIMO.Excel.ExcelDocument

Renames a defined name.

Syntax

Rename-OfficeExcelNamedRange
[-Document <ExcelDocument>]
[-Global]
[-Name] <String>
[-NewName] <String>
[-PassThru]
[-Sheet <OfficeSheetSelector>]
[-ValidationMode <Sanitize|Strict>]
[<CommonParameters>]
#
Parameter set: Default

Examples

Rename a defined name

Open-OfficeExcel -Path .\Finance\Budget-2027.xlsx {
    Rename-OfficeExcelNamedRange Rate TaxRate
}

Renames Rate to TaxRate; formulas that use the name follow the change.

Apply a naming convention

$names = Get-OfficeExcelNamedRange -Path .\Finance\Pricing-Model.xlsx | Where-Object SheetName -eq 'Inputs'
Open-OfficeExcel -Path .\Finance\Pricing-Model.xlsx {
    foreach ($name in $names) {
        Rename-OfficeExcelNamedRange -Name $name.Name -NewName "in_$($name.Name)" -ValidationMode Strict
    }
}

Prefixes every input name of the pricing model with in_ so inputs are easy to tell apart from calculations.

Parameters

-Document ExcelDocument optionalpipeline: True (ByValue)
Caller-owned workbook; omission uses the enclosing Excel content block.
-Global SwitchParameter optional
Use workbook-global scope from inside the DSL.
-Name String requiredposition: 0
Named range name.
-NewName String requiredposition: 1
New named range name.
-PassThru SwitchParameter optional
Emits the native result after the operation.
-Sheet OfficeSheetSelector optional
Worksheet name, one-based position or native worksheet object. Multi-sheet commands also accept wildcard names.
-ValidationMode ExcelDefinedNameValidationMode optional
Defined-name validation mode.
Possible values: Sanitize, Strict

Common Parameters

This command supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.

For more information, see about_CommonParameters.