Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

default property of an object 1

Status
Not open for further replies.

venkman

Programmer
Oct 9, 2001
467
US
Is there a way to set the default property of a user-defined object. Like Range's default property is Value. If I had a class CVenkman with a get-able and let-able property PVenkman of type long. Is there a way to set PVenkman to be the default property so that the following code would not raise an error:

dim myClass as CVenkman
set myClass = New CVenkman
myClass = 10
msgbox myClass

Thanks
-Venkman
 
Venkman,

you sure can: all you need to do is export your class,
Open the class file in Notepad
Add the line
Code:
Attribute Value.VB_UserMemId = 0
to the property you want to set as default
Save class
Import into Excel
and you should now have it sat

There's a few things to be aware of:
you will not see the line in the VBA Editor
and I think there's been issues with it disappearing when the class is edited/recompiled - but I ain't sure on that one

It's a heck of a long time ago I used this, so I can't remember it all offhand (getting old) ;-)
Also, I used this in Access rather than Excel, but as far as I understood it should work in both

HTH

Cheers
Nikki
 
BTW: the line needs to be added as second line of your Property Get statement!

Cheers
Nikki ;-)

(told you I was getting old!)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top