我有一个类ValidationChanger
,它的方法changeNamedRangeAddress
应该更改RefersTo
命名范围的地址。但是,我的代码意外地将新地址用双引号括起来。
这里的类定义ValidationChanger
:
'ValidationChanger
Sub changeNamedRangeAddress(bk As Workbook, rangeName As String, newAddress As String)
bk.Names(rangeName).RefersTo = newAddress
End Sub
我在一个名为 的范围内对其进行测试,该范围TestRange
指的是 sheet Instructions
:中的地址Instructions!$A$133:$A$138
。我的测试应该将地址更改为Instructions!$A$133:$A$139
以下内容:
Sub testValidationChanger()
Dim vc As New ValidationChanger
Dim bk As Workbook
Set bk = Workbooks("test.xlsm")
Debug.Print bk.Names("TestRange").RefersTo
vc.changeNamedRangeAddress bk, "TestRange", "Instructions!$A$133:$A$139"
Debug.Print bk.Names("TestRange").RefersTo
End Sub
输出是:
=Instructions!$A$133:$A$138
="Instructions!$A$133:$A$139"
知道为什么新地址用双引号括起来(这使它用作文本字符串而不是地址)?