我正在尝试创建一个类模块,以在工作簿中构建一些基本的数据库功能。我遇到的问题是尝试将工作表添加为类成员。我不断收到“无效使用财产”的错误。
我的班级声明:
Option Explicit
Private pboolLock As Boolean
Private pintColCount, pintRowCount As Integer
Private pWorksheet As Excel.Worksheet
'Lock bit properties:
Property Get boolLock() As Boolean
boolLock = pboolLock
End Property
Property Let boolLock(boollockval As Boolean)
pboolLock = boollockval
End Property
'Utility properties- no sets
Property Get ColCount() As Integer
ColCount = pintColCount
End Property
Property Get RowCount() As Integer
RowCount = pintRowCount
End Property
'Worksheet specific props
Property Set dpDefine(ByRef wks As Worksheet)
Set pWorksheet = wks
End Property
Property Get dpDefine() As Worksheet
dpDefine = pWorksheet
End Property
不同的模块:类实例化:
Sub tryClass()
Dim thisdp As New Cdatapage
Dim iansTest As String
iansTest = Sheets("typical datapage").Name
'this works, so reference is being passed:
MsgBox ("The name is " & iansTest)
'this doesn't work:
thisdp.dpDefine (Sheets("typical datapage"))
End Sub
有什么建议吗?感谢。
答案 0 :(得分:1)
它是Set
属性,因此您需要:
Set thisdp.dpDefine = Sheets("typical datapage")
或者,如果您将dpDefine
更改为Let
,则可以;
thisdp.dpDefine = Sheets("xxx")