是否可以让函数获取指示对象名称的字符串,然后返回相应的 UserForm 对象作为结果?
Function foo(name as string) as Object dim Obj as Object ' code to do the job set foo = Obj End Function
尝试这样的事情:
Option Explicit
Private Sub Test()
Dim f As Object
Set f = GetForm("UserForm2")
f.Show
End Sub
Private Function GetForm(ByVal Name As String) As Object
Set GetForm = UserForms.Add(Name)
End Function