VBA - 需要:获取 UserForm 对象并给出其名称

问题描述 投票:0回答:1

是否可以让函数获取指示对象名称的字符串,然后返回相应的 UserForm 对象作为结果?

Function foo(name as string) as Object dim Obj as Object ' code to do the job set foo = Obj End Function

vba controls userform
1个回答
0
投票

尝试这样的事情:

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
© www.soinside.com 2019 - 2024. All rights reserved.