VBA类模块:从类中的对象获取属性

时间:2018-05-16 19:15:32

标签: excel-vba class properties vba excel

我有一个包含一些属性和控件元素的类模块。如何在班级活动中获得这些控件的属性值?我试过了

me.property 

control.parent.property 

但没有奏效。我认为应该有一种方法来解决模块内部类模块的每个实例的属性,是吗?

我的课程模块:Cworker

Public WithEvents img1 As MSForms.Image
Private AcnS
Dim rng1 As Range, rng2 As Range, rng3 As Range

' Property Definitions

Public Property Get Aircraft() As String
    Aircraft = Acn
End Property
Public Property Let Aircraft(Value As String)
    Acn = Value
End Property

' Events Procedures

Private Sub img1_Click()  ' Showing Progress Form
    With ThisWorkbook.Sheets("Performance")
        Set rng1 = .Range("ProgCrit")
        Set rng2 = .Range("Progress")
        Set rng3 = .Range("op_log")
    End With
    frmprogress.LAc = Me.Aircraft 
    rng1.Cells(2, 1) = Me.Aircraft 
    rng3.AdvancedFilter xlFilterCopy, rng1, rng2
    oprecord.Calculate
    frmprogress.Show
End Sub

Tahnks, 中号

1 个答案:

答案 0 :(得分:2)

我认为你在第二行有一个错字: 我认为,根据我的测试,您可以参考me.property,没有前缀的属性本身,以及您指定的类变量。你也可以尝试一下。

Public WithEvents img1 As MSForms.Image
Private Acn$ ' As String if you meant!
Dim rng1 As Range, rng2 As Range, rng3 As Range

' Property Definitions

Public Property Get Aircraft() As String
    Aircraft = Acn
End Property
Public Property Let Aircraft(Value As String)
    Acn = Value
End Property

' Events Procedures

Private Sub img1_Click()  ' Showing Progress Form
    With ThisWorkbook.Sheets("Performance")
        Set rng1 = .Range("ProgCrit")
        Set rng2 = .Range("Progress")
        Set rng3 = .Range("op_log")
    End With
    frmprogress.LAc = Me.Aircraft 
    rng1.Cells(2, 1) = Me.Aircraft 
    rng3.AdvancedFilter xlFilterCopy, rng1, rng2
    oprecord.Calculate
    frmprogress.Show
End Sub