1

尝试在 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
4

2 回答 2

4

您的Let方法应该使用value参数:

Public Property Let affBuild(value As String)
    buildWs = value
End Property

Public Function activate()没有返回任何价值。

也许,您应该使用Public Sub activate().

于 2012-04-20T15:29:37.853 回答
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开始学习课程。

布鲁斯

于 2012-04-20T15:03:10.563 回答