2013-01-18 76 views
0

我想分配一個命名範圍的值的變量數組。我幾乎在賦值代碼 Material = ThisWorkbook.Names(「RMInStoreName」)處得到應用程序或對象定義的錯誤。RefersToRange 我從here得到了這個例子,並在成功之前使用了它。對象定義錯誤與指定命名範圍數組

我仍然試圖找出爲什麼這個錯誤顯示出來,我似乎已經用完了想法,任何人都可以幫助我指向正確的方向將真正節省我很多 代碼低於 這裏是代碼

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 

感謝您的幫助 斯蒂芬

+0

您的代碼段將無法編譯。在「狀態」前需要一個「Dim」。 –

回答

0

最可能的原因是,你不必所有工作簿中定義的命名範圍。

您可以使用公式選項卡驗證命名範圍。

公式 - >名稱管理器

enter image description here

0

RefersToRange會返回一個範圍對象。它的你是那麼後的值:

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

,或者您可以使用:

Material = Evaluate("RMInStoreName") 

或:

Material = Evaluate(ThisWorkbook.Names("RMInStoreName").RefersTo).Value 
相關問題