hi I would like to load and unload a user form by calling formtimer with a string as the form name not sure how I would go about it ,i would love some input
Public Sub callme()
FormTimer ("UserForm1")
End Sub
public Sub FormTimer(Fname As String)
Fname.Show vbModeless
Application.OnTime Now TimeValue("00:00:02"), "UnloadIt(Fname)"
End Sub
Public Sub UnloadIt(name As string)
Unload name
End Sub
CodePudding user response:
Try the following code...
Public Sub callme()
FormTimer "UserForm1"
End Sub
Public Sub FormTimer(Fname As String)
VBA.UserForms.Add(Fname).Show vbModeless
Application.OnTime Now TimeValue("00:00:02"), "'UnloadIt """ & Fname & """'"
End Sub
Public Sub UnloadIt(name As String)
Dim uf As Object
For Each uf In VBA.UserForms
If uf.name = name Then
Unload uf
Exit Sub
End If
Next uf
End Sub