使用Range初始化vba类成员variables

我创build了一个成员variablestypes为range的类。 现在,如果我尝试初始化或设置该范围的值I错误:对象variables或未设置块variables。 现在我认为这是因为它被初始化为Nothing,但是如果我使用class Sub Class_Initialize并尝试在那里设置默认值,它仍然错误。 那么给了什么?

Private pRng As Range Private pstype As Boolean Public Property Get Rng() As Range Rng = pRng End Property Public Property Let Rng(Value As Range) pRng = Value End Property Public Property Get Stype() As Boolean Stype = pstype End Property Public Property Let Stype(Value As Boolean) pstype = Value End Property Private Sub Class_Initialize() pRng = Range("A1") pstype = True End Sub 

您需要使用Set关键字来初始化或设置范围,例如:

 Set Rng = pRng Set pRng = Value