I am using a Class Module to define a class. It has properties, but I would like to make one of those properties the default. How do I do that?
I am using a Class Module to define a class. It has properties, but I would like to make one of those properties the default. How do I do that?
In the VBIDE, export the class module.
Open the exported file in a text editor.
Look for the property Get for your target property and add this line
Attribute Value.VB_UserMemId = 0
So that the property will now be something like
[vba]
Property Get StartYear() As Long
Attribute Value.VB_UserMemId = 0
StartYear = mStartYear
End Property
[/vba]
Last edited by Bob Phillips; 06-02-2007 at 12:25 PM.
many thanks
Bad News. It apparently doesn't work on Mac.s
I should mention someting in the Mac forum, but Excel 2004 doesn't have an Export option on the menu, so I'm not too surprised
When I wrote my own export/import and followed those instructions. I could not see the added line, and the code ran as if there were nothing there.
Bummer.
This might help...
http://vbaexpress.com/kb/getarticle.php?kb_id=795
Steve
"Nearly all men can stand adversity, but if you want to test a man's character, give him power."
-Abraham Lincoln
Thank you lucas and BlueCactus. That is a sweet utility for a Mac user.
Unfortunatly, I can't get it to assign a property as the default.
The module exports and imports fine, but the Default properties of custom classes may not be supported by Mac.
I noticed something. I exported the module, inserted the line with Text Edit, saved the file and imported it. Viewed through the VB editor, the inserted line had been removed. The line count wasn't changed , but there were no (visible) characters. When I exported the modified module and inspected that new export with Text Edit, the inserted code was gone. Excel 2004 removed that instruction.
I guess not everything about Mac is wonderful...
sorry I just couldn't resist
Steve
"Nearly all men can stand adversity, but if you want to test a man's character, give him power."
-Abraham Lincoln
Mac doesn't need every thing to be wonderful, just more things than a PC.Originally Posted by lucas
Well, at its inflated price tag and its crippled functionality, I guess it needs something.
Now, now, boys and girls!!!
Semper in excretia sumus; solum profundum variat.