我一直在嘗試學習如何在Excel VBA中創建自定義集合,並在MSDN上找到這段代碼。雖然我理解它的大部分,誰能告訴我最後的代碼Set Add = empNew
在做什麼?我不明白這是評論。謝謝!VBA自定義集合對象
' Methods of the Employees collection class.
Public Function Add(ByVal Name As String, _
ByVal Salary As Double) As Employee
Dim empNew As New Employee
Static intEmpNum As Integer
' Using With makes your code faster and more
' concise (.ID vs. empNew.ID).
With empNew
' Generate a unique ID for the new employee.
intEmpNum = intEmpNum + 1
.ID = "E" & Format$(intEmpNum, "00000")
.Name = Name
.Salary = Salary
' Add the Employee object reference to the
' collection, using the ID property as the key.
mcolEmployees.Add empNew, .ID
End With
' Return a reference to the new Employee.
Set Add = empNew
End Function
當你調用'Add()'方法時,這一行只是返回創建的'empNew' instanse結果。 – omegastripes