gpt4 book ai didi

class - 使 Excel 工作表成为类模块成员

转载 作者:行者123 更新时间:2023-12-04 20:47:38 24 4
gpt4 key购买 nike

我正在尝试创建一个类模块来在工作簿中构建一些基本的数据库功能。我遇到的问题是尝试将工作表添加为类(class)成员。我不断收到“无效使用属性(property)”作为错误。

我的类(class)声明:

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

有什么建议么?谢谢。

最佳答案

它是 Set属性(property),所以你需要:

Set thisdp.dpDefine = Sheets("typical datapage")

或者,如果您更改 dpDefineLet你可以;
thisdp.dpDefine = Sheets("xxx")

关于class - 使 Excel 工作表成为类模块成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8416821/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com