2013-01-04 102 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

相关问题