VBA / VB中的类方法

当试图在VBA中使用一个类时,我总是得到一个下标超出范围的错误,并可以在这里使用一些帮助!

这是class级 –

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 

这是错的

 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/classs入门课程。

布鲁斯

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

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

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

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