我在通过给定引用(Workbook
)获取RefersTo
对象的名称时遇到问题。代码如下:
Sub add()
ThisWorkbook.Names.add Name:="Letee", RefersTo:="Nazwa2"
MsgBox ThisWorkbook.Names(RefersTo:="Nazwa2")
End Sub
答案 0 :(得分:1)
确保 Nazwa2 是有效名称:
Sub add()
Sheets(1).Range("A1").Name = "Nazwa2"
ThisWorkbook.Names.add Name:="Letee", RefersTo:="Nazwa2"
MsgBox ThisWorkbook.Names(1)
End Sub
要查看名称链:
Sub addx()
Sheets(1).Range("A1").Name = "Nazwa2"
ThisWorkbook.Names.add Name:="Letee", RefersTo:="Nazwa2"
i = 1
For Each nm In ActiveWorkbook.Names
Cells(i, 1).Value = nm.Name
Cells(i, 2).Value = "'" & nm.RefersTo
i = i + 1
Next
End Sub