View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Jeremy Gollehon[_2_] Jeremy Gollehon[_2_] is offline
external usenet poster
 
Posts: 35
Default Hide/Show modeless userform when activating/deactivating workbooks

I''ve written the following code to make sure a modeless form hides if the
user activates another workbook while the form is showing. I'm posting to
see if there are better ways.

I dimension a public variable in a regular code module:
Public ShowUserForm1 As Boolean

In the ThisWorkbook object module I have:
-----------------------------------------------------------------------
Private Sub Workbook_Activate()
If ShowUserForm1 Then UserForm1.Show
End Sub

Private Sub Workbook_Deactivate()
If UserForm1.Visible = True Then
UserForm1.Hide
ShowUserForm1 = True
End If
End Sub
-----------------------------------------------------------------------


In the Terminate code of the Userform I have:
-----------------------------------------------------------------------
Private Sub UserForm_Terminate()
ShowUserForm1 = False
End Sub
-----------------------------------------------------------------------


This works great (as far as I've been able to test). Is there a better way?
Thanks!

-Jeremy