PDA

View Full Version : Solved: Custom Class - Property Set Question



mantooth29
01-01-2013, 11:02 AM
Hello,

I am trying to simplify the client code for my classes, and am wondering if I can set properties of objects like this...


With myClass

.SourceWorkbook = ThisWorkbook
End With



as opposed to this



Set myClass.Sourceworkbook = ThisWorkbook



The corresponding Properties in the class module look like this



Dim pSourceWorkbook as Excel.Workbook

Property Get SourceWorkbook() as Excel.Workbook

Set SourceWorkbook = pSourceWorkbook
End Property

Property Set SourceWorkbook(ByRef Value as Excel.Workbook)

Set pSourceWorkbook =Value
End Property




Is this possible? When attempting as I have written, I get the usual "Object Variable or With Block Variable not set" error.

Paul_Hossler
01-01-2013, 12:37 PM
A little bit more simple, but AFAIK objects always require the 'Set' in assignments


With myClass
Set .SourceWorkbook = ThisWorkbook
End With


Paul

Bob Phillips
01-01-2013, 05:59 PM
I think that what he is saying is that he wants to do away with the set because the class is doing the set. If this is correct, the answer is no, all objects must be set, even if the setting is to invoke another object being set.

mantooth29
01-01-2013, 09:41 PM
Yes that is correct xld.

I have tried Paul's suggestion as well, but if I use multiple objects I won't like how the code starts to look.

I think that I will use a friend method to set all the objects in a one liner.

Thanks guys!