PDA

View Full Version : Setting Default Property in a Class Module



mikerickson
06-02-2007, 09:14 AM
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?

Bob Phillips
06-02-2007, 11:20 AM
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




Property Get StartYear() As Long
Attribute Value.VB_UserMemId = 0
StartYear = mStartYear
End Property

mikerickson
06-02-2007, 12:14 PM
many thanks

mikerickson
06-02-2007, 05:07 PM
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.

lucas
06-02-2007, 06:31 PM
This might help...
http://vbaexpress.com/kb/getarticle.php?kb_id=795

mikerickson
06-02-2007, 07:14 PM
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.

lucas
06-03-2007, 08:56 AM
I guess not everything about Mac is wonderful...:devil2:

sorry I just couldn't resist

mikerickson
06-03-2007, 10:41 AM
I guess not everything about Mac is wonderful...:devil2:
Mac doesn't need every thing to be wonderful, just more things than a PC. ;)

Bob Phillips
06-03-2007, 10:53 AM
Well, at its inflated price tag and its crippled functionality, I guess it needs something.

paulked
06-04-2007, 09:05 PM
Now, now, boys and girls!!!