VBA/Excel/Access/Word/Excel/Name Create — различия между версиями

Материал из VB Эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 12:47, 26 мая 2010

Add the name to the Names collection associated with the worksheet, which only includes the names that are local to that worksheet

 
Sub nameRef()
     Worksheets("Sheet1").Names.add name:="Costs", RefersTo:="=Sheet1!$F$10:$F$12"
End Sub
"Using the Name Property of the Range Object
Sub name()
     range("A1:D10").name = "SalesData"
End Sub



create a global name that refers to a range using the Add method of the Workbook object"s Names collection

 
Sub add()
     Names.add name:="Data", RefersTo:="=Sheet1!$D$10:$D$12"
End Sub



Create a local name

 
Sub localDemo()
     Names.add name:="Sheet1!Sales", RefersTo:="=Sheet1!$E$10:$E$12"
End Sub



Create a name based on a Range

 
Sub nameName()
    range("A1:F6").name = "Fruits"
End Sub



Define a name by referring a workbook

 
Sub DefineName3()
  ActiveWorkbook.names.Add Name:="WorkArea", RefersTo:="=" + ActiveWorkbook.Sheets("sheet1").[A1].CurrentRegion.Address(External:=True)
  Debug.Print Range("WorkArea").Address(External:=True)
End Sub



Define a name by referring the selection cell address

 
Sub DefineName2()
  ActiveWorkbook.Activate
  [A1].CurrentRegion.Activate
  ActiveWorkbook.Names.Add Name:="WorkArea", RefersTo:="=" + Selection.Address
  Debug.Print Range("WorkArea").Address(External:=True)
End Sub



renames an existing name:

 
Sub nameName2()
    Names("Fruits").name = "Produce"
End Sub