2013-01-04 103 views
1

我有一個簡單的屬性(pName)自己的類(ClassFoo),我無法設置它,因爲我總是得到錯誤...Excel 2010 VBA - 錯誤:對象變量或與塊變量未設置

Class Modules - ClassFoo 
--- 
Public pName as String 

Public Property Let Name(Value as String) 
    pName = Value 
End Property 
---- 
Somewhere else in the ModuleX 
... 
Dim Foo as ClassFoo 
Foo.Name = "foo" <- throws error 
Foo.pName = "foo" <- throws error 

With Foo 
.pName = "foo" <- throws error 
End With 

我改變了類的實例化「從「民營」到「PublicNotCreatable」(來回) 但我仍然有同樣的錯誤...

感謝˚F或提前回復。

回答

5

你需要創建一個實例&將其分配給Foo左右;

Dim Foo as ClassFoo 
Set Foo = new ClassFoo 
+0

感謝您的幫助!它的工作原理 – cscsaba

2

您需要實例化它,我相信嘗試

Dim foo as new ClassFoo 
+0

感謝您的幫助! – cscsaba

相關問題