Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel 2010 VBA - error : Object variable or With Block variable not set

I have an own class (ClassFoo) with a simple property (pName), and I could not set it, because I always get error ...

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 

or

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

I changed the class 'Instancing' from 'Private' to 'PublicNotCreatable' (back and forth) But I still have the same error ...

Thanks for the replies in advance.

Cs

like image 909
cscsaba Avatar asked Jul 18 '26 10:07

cscsaba


2 Answers

You need to create an instance & assign it to Foo so;

Dim Foo as ClassFoo
Set Foo = new ClassFoo
like image 106
Alex K. Avatar answered Jul 21 '26 04:07

Alex K.


You need to instantiate it I believe try

 Dim foo as new ClassFoo
like image 37
Bmo Avatar answered Jul 21 '26 04:07

Bmo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!