我在工作表中有员工详细信息,并且我将所有数据加载到我创建的几个员工类对象中。根据用户在GUI工具上选择的条件,我想使用我最初创建/加载的类对象来显示数据。
Function loadEmpData() As Employee()
Dim e() As New Employee
With dataSheet
no_of_emp = .Range(.Range("a4"), .Range("a4").End(xlDown)).Count
' no_of_emp = .Range(.Range("a3"), .Range("a3").End(xlDown)).Offset(1, 0).SpecialCells(xlCellTypeVisible).Count
' .Range(.Range("a3"), .Range("a3").End(xlDown)).SpecialCells(xlCellTypeVisible).Copy clsTest.Range("a1")
'MsgBox no_of_emp - 1
no_of_emp = no_of_emp - 1
ReDim e(no_of_emp) As New Employee
xc = 4
yc = 1
zc = 0
Do While zc <= no_of_emp
e(zc).EmpID = .Cells(xc, 1).Value
e(zc).Fname = .Cells(xc, 2).Value
e(zc).Lname = .Cells(xc, 3).Value
e(zc).Band = .Cells(xc, 6).Value
e(zc).EmpTitle = .Cells(xc, 7).Value
e(zc).SecondLR = .Cells(xc, 12).Value
e(zc).LR = .Cells(xc, 13).Value
On Error Resume Next
e(zc).Acc_Know = .Cells(xc, 15).Value
e(zc).Ref_Acc_Know = .Cells(xc, 16).Value
e(zc).Analytic = .Cells(xc, 17).Value
e(zc).Ref_Analytic = .Cells(xc, 18).Value
e(zc).Sys_Know = .Cells(xc, 19).Value
e(zc).Ref_Sys_Know = .Cells(xc, 20).Value
e(zc).Ssigma = .Cells(xc, 21).Value
e(zc).Ref_Ssigma = .Cells(xc, 22).Value
e(zc).Quality_focus = .Cells(xc, 23).Value
e(zc).Ref_Quality_focus = .Cells(xc, 24).Value
e(zc).Risk_mgmt = .Cells(xc, 25).Value
e(zc).Ref_Risk_mgmt = .Cells(xc, 26).Value
e(zc).Transition_mgmt = .Cells(xc, 27).Value
e(zc).Ref_Transition_mgmt = .Cells(xc, 28).Value
e(zc).stakehold_orient = .Cells(xc, 29).Value
e(zc).Ref_stakehold_orient = .Cells(xc, 30).Value
e(zc).atten_details = .Cells(xc, 31).Value
e(zc).Ref_atten_details = .Cells(xc, 32).Value
e(zc).Accountability = .Cells(xc, 33).Value
e(zc).Ref_Accountability = .Cells(xc, 34).Value
e(zc).collab_team = .Cells(xc, 35).Value
e(zc).Ref_collab_team = .Cells(xc, 36).Value
e(zc).comm_skills = .Cells(xc, 37).Value
e(zc).Ref_comm_skills = .Cells(xc, 38).Value
e(zc).achieve_results = .Cells(xc, 39).Value
e(zc).Ref_achieve_results = .Cells(xc, 40).Value
e(zc).strategic_orient = .Cells(xc, 41).Value
e(zc).Ref_strategic_orient = .Cells(xc, 42).Value
e(zc).behaviour = .Cells(xc, 43).Value
e(zc).Ref_behaviour = .Cells(xc, 44).Value
e(zc).build_strong_org = .Cells(xc, 45).Value
e(zc).Ref_build_strong_org = .Cells(xc, 46).Value
e(zc).DFP = .Cells(xc, 49).Value
On Error GoTo 0
' clsTest.Cells(xc, 1).Value = e(zc).EmpID
' clsTest.Cells(xc, 2).Value = e(zc).Fname
' clsTest.Cells(xc, 3).Value = e(zc).Lname
' clsTest.Cells(xc, 4).Value = e(zc).FunctionGroup
' clsTest.Cells(xc, 5).Value = e(zc).ProcessGroup
' clsTest.Cells(xc, 6).Value = e(zc).Band
zc = zc + 1
xc = xc + 1
Loop
' MsgBox e(12).EmpID
' MsgBox e(12).Band
End With
End Function
我创建的这些对象,我想在同一个项目的子对象中使用它们。可能吗?我在网上搜索了很多,并没有接近解决方案。
员工类:
Public EmpID As String
Public Fname As String
Public Lname As String
Public FunctionGroup As String
Public ProcessGroup As String
Public Band As String
Public EmpTitle As String
Public SecondLR As String
Public LR As String
Public DFP As Integer
Public Acc_Know As Integer
Public Analytic As Integer
Public Sys_Know As Integer
Public Ssigma As Integer
Public Quality_focus As Integer
Public Risk_mgmt As Integer
Public Transition_mgmt As Integer
Public stakehold_orient As Integer
Public atten_details As Integer
Public Accountability As Integer
Public collab_team As Integer
Public comm_skills As Integer
Public achieve_results As Integer
Public strategic_orient As Integer
Public behaviour As Integer
Public build_strong_org As Integer
Public Ref_Acc_Know As Integer
Public Ref_Analytic As Integer
Public Ref_Sys_Know As Integer
Public Ref_Ssigma As Integer
Public Ref_Quality_focus As Integer
Public Ref_Risk_mgmt As Integer
Public Ref_Transition_mgmt As Integer
Public Ref_stakehold_orient As Integer
Public Ref_atten_details As Integer
Public Ref_Accountability As Integer
Public Ref_collab_team As Integer
Public Ref_comm_skills As Integer
Public Ref_achieve_results As Integer
Public Ref_strategic_orient As Integer
Public Ref_behaviour As Integer
Public Ref_build_strong_org As Integer
答案 0 :(得分:2)
我无权访问您的Employee类模块,但您需要该函数来返回新数组。
远离公共场合;从函数中传回值数组是更好的方法。
Function loadEmpData() As Employee()
Dim e() As New Employee
'... lots of code here
loadEmpData = e
end function
然后在像这样的子中调用加载函数。
sub WorkWithEmployees()
Dim a as long, emps() As New Employee
emps = loadEmpData()
for a=lbound(emps, 1) to ubound(emps, 1)
debug.print emps(a).EmpID
next a
end sub