ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Hide/Show modeless userform when activating/deactivating workbooks (https://www.excelbanter.com/excel-programming/275590-hide-show-modeless-userform-when-activating-deactivating-workbooks.html)

Jeremy Gollehon[_2_]

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




All times are GMT +1. The time now is 02:43 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com