dmwatson0101
dmwatson0101

Reputation: 27

Class methods in VBA / VB

When trying to use a class in VBA I keep getting a subscript out of range error and could use some help here!

This is the 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

This is the call -

Sub SetWs()
    Dim current As CBuildSheet
    Set current = New CBuildSheet
    current.affBuild = "Resource Entry"
    current.activate
End Sub

Upvotes: 1

Views: 1849

Answers (2)

Francis P
Francis P

Reputation: 13655

Your Let method should be using the value parameter:

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

Your Public Function activate() is not returning any value.

Perhaps, you should use Public Sub activate().

Upvotes: 4

bruce
bruce

Reputation: 1408

this is wrong...

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

and should be...

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

see . http://ramblings.mcpher.com/Home/excelquirks/snippets/classes for getting started with classes.

Bruce

Upvotes: 3

Related Questions