xlf | xlfAddNameScope macro
xlfAddNameScope - Name Manager view
Here is the VBA code to add Defined Names to a workbook with Scope as Workbook or Worksheet. The resultant names appear in figure 1.

xlfAddNameScope - the VBA code
Code 1: Macro
xlfAddNameScope
add defined names to workbook with WS and WS scope
Sub xlfAddNameScope() ' WorkBook scope ======== With ActiveWorkbook .Names.Add Name:="WBscope", _ RefersToR1C1:="=Sheet1!R6C4" ' absolute reference .Names("wbscope").Comment = " - name is unique in the workbook" End With ' WorkSheet scope ======= With ActiveWorkbook.Worksheets("Sheet1") .Names.Add Name:="WSscope", _ RefersToR1C1:="=Sheet1!R8C4" .Names("wsscope").Comment = " - name is unique in the worksheet" End With End Sub
- Development platform: Office 365 ProPlus (16.0.11328.20156) 64 bit
- Published: 15th March 2019
- Revised: Friday 24th of February 2023 - 03:12 PM, Pacific Time (PT)