当试图在VBA中使用一个类时,我不断得到一个超出范围的下标错误,可以在这里使用一些帮助!
这是班级 -
Option Explicit
Private buildWs As String
Public Property Get affBuild() As String
affBuild = buildWs
End Property
Public Property Let affBuild(value As String)
buildWs = affBuild
End Property
Public Function activate()
Sheets(buildWs).activate
End Function
这是电话 -
Sub SetWs()
Dim current As CBuildSheet
Set current = New CBuildSheet
current.affBuild = "Resource Entry"
current.activate
End Sub
答案 0 :(得分:4)
您的Let
方法应该使用value
参数:
Public Property Let affBuild(value As String)
buildWs = value
End Property
您的Public Function activate()
未返回任何值。
也许,你应该使用Public Sub activate()
。
答案 1 :(得分:3)
这是错误的......
Public Property Let affBuild(value As String)
buildWs = affBuild
End Property
应该是......
Public Property Let affBuild(value As String)
buildWs = value
End Property
看。 http://ramblings.mcpher.com/Home/excelquirks/snippets/classes开始上课。
布鲁斯