0

我正在尝试将命名范围的值分配给变量数组。我几乎在分配代码 Material = ThisWorkbook.Names("RMInStoreName").RefersToRange 级别收到应用程序或对象定义的错误,我从这里得到了这个例子,并且在成功之前使用过它。

我仍在试图弄清楚为什么会出现此错误,我似乎已经没有想法了,任何人都可以帮助我指出正确的方向将真正为我节省很多代码在下面这是代码

 Sub MonitorStore()
Dim ThreshHold As Variant, InStore As Variant, StatusReport As Variant
Dim Material As Variant    'is the name of the material
Status As Variant
'status is a variable which holds data on wether the user  has seen msg and 
'wants to     supress msg
'the ThreshHold is the minimum allowed in store below which messages are firerd
'InStore is the volume of materials currently in store
'and be told of another error after solving error one, report all at once


 Material = ThisWorkbook.Names("RMInStoreName").RefersToRange
ThreshHold = ThisWorkbook.Names("RMThreshHold").RefersToRange
InStore = ThisWorkbook.Names("RMInStore").RefersToRange
Status = ThisWorkbook.Names("RMStatus").RefersToRange

'other code.............
'dont expect error from unexecuted code
End Sub

感谢斯蒂芬的帮助

4

2 回答 2

0

RefersToRange 将返回一个范围对象。它是你之后的价值:

Material = ThisWorkbook.Names("RMInStoreName").RefersToRange.Value

或者您可以使用:

Material = Evaluate("RMInStoreName")

或者:

Material = Evaluate(ThisWorkbook.Names("RMInStoreName").RefersTo).Value
于 2013-02-06T11:59:09.223 回答
0

最可能的原因是您没有在工作簿中定义所有命名范围。

您可以使用“公式”选项卡验证命名范围。

公式 --> 名称管理器

在此处输入图像描述

于 2013-01-18T18:39:08.290 回答