0
我想教自己如何使用vba類模塊。這是我的班級模塊(名爲clsWorkingRange
)。這裏的模塊:class property not working excel vba
Option Explicit
Private pSheetName As String
Private pColNum As Integer
Public Property Get SheetName() As String
SheetName = pSheetName
End Property
Public Property Let SheetName(SheetName As String)
pSheetName = SheetName
End Property
Public Property Get ColNum() As Integer
ColNum = pColNum
End Property
Public Property Let ColNum(ColNumb As Integer)
pColNum = ColNum
End Property
Public Function Get_Rows_Generic(work_sheet_get As String, column_num As Integer)
'worksheet is the name of a sheet in the form of a string
Dim ws As Worksheet: Set ws = Worksheets(work_sheet_get)
Dim rows_count As Long: rows_count = ws.Cells(rows.Count, column_num).End(xlUp).Row
Get_Rows_Generic = rows_count
End Function
我想在這裏起訴類(在一個單獨的模塊):
Option Explicit
Sub test_the_class()
Dim first_class_example As New clsWorkingRange
first_class_example.SheetName = "agentsFullOutput.csv"
first_class_example.ColNum = 1
Debug.Print first_class_example.SheetName
Debug.Print first_class_example.ColNum
Dim row_count_test As Long
row_count_test = first_class_example.Get_Rows_Generic(first_class_example.SheetName, first_class_example.ColNum)
MsgBox "row count is " & row_count_test
End Sub
Debug.Print first_class_example.ColNum
打印0
。爲什麼不是財產通過1?
我有多愚蠢?謝謝。 – dwstein