Forms vba,用户窗体显示方法
有人能给我解释一下为什么显示形式和隐藏形式的方式是不同的吗 显示表单的代码 userform1.show 和代码来隐藏它 卸载userform1 为什么没有完成userform1.unload? 为什么卸载写在userform前面Forms vba,用户窗体显示方法,forms,vba,methods,Forms,Vba,Methods,有人能给我解释一下为什么显示形式和隐藏形式的方式是不同的吗 显示表单的代码 userform1.show 和代码来隐藏它 卸载userform1 为什么没有完成userform1.unload? 为什么卸载写在userform前面 提前谢谢。UserForm类有Show和Hide方法。使用Show将显示已存在内存中的表单实例,使用Hide将隐藏它。隐藏表示实例仍在内存中且可访问,但不可见 在VBA.Global命名空间中,有方法Load和Unload。使用Load可以将对象加载到内存中,但不可
提前谢谢。
UserForm
类有Show
和Hide
方法。使用Show
将显示已存在内存中的表单实例,使用Hide
将隐藏它。隐藏表示实例仍在内存中且可访问,但不可见
在
VBA.Global
命名空间中,有方法Load
和Unload
。使用Load
可以将对象加载到内存中,但不可见,需要调用Show
方法来显示表单。使用Unload
卸载表单,表单将从内存中删除,并且不再可访问
因此,Show/Hide
和Load/Unload
是处理表单的两种不同方式
IMO:最简单的方法是创建一个类型的变量,例如UserForm1
,然后使用这个变量。此变量包含对UserForm1
的引用,可用于显示或隐藏表单
Dim frm1 As UserForm1
Set frm1 = New UserForm1 ' Creates new instance in memory but does not display it yet
frm1.Show ' Displays the form
frm1.Hide ' Hides form but it remains in memory and is still accessible
set frm1 = Nothing ' Removes connection between variable frm1 and form instance.
' If no other references are available the form instance can be removed from memory
您可以使用UserForm1.Hide关闭它