When you display the form, you are likely doing something like:
UserForm.Show
The Show
method takes an optional argument, whether to display the form Modal
or Modeless
. Modal display is default, and does not allow interaction with the worksheet/workbook objects. Instead, when you display the form, do:
UserForm.Show vbModeless
This will allow the user to interact with the worksheet/workbook, which alleviates the need for your custom button and you will not need to do Me.Hide
. Minimizing the Application will minimize the UserForm. Maximizing the Application will re-display the workbook and the userform.
If you must use the vbModal
display of the UserForm (and in many applications this is a deliberate requirement to prevent user from interacting with the Workbook/Worksheets), let me know. There may be some events or application events that could better trap the minimize/maximize.
UPDATE
Alternatively, you could do something like this. This approach Hides the Excel Application, and shrinks the size of the UserForm, then resizes it when you click back on the user form and shows the Excel Application again.
Private Sub CommandButton15_Click()
'Hide Excel and minimize the UserForm
Application.Visible = False
Me.Height = 10
Me.Width = 10
End Sub
Private Sub UserForm_Click()
'Show Excel and resize the UserForm
Application.Visible = True
Me.Height = 180
Me.Width = 240
End Sub
Private Sub UserForm_Terminate()
'Ensure that the Application is visible and the form resized
UserForm_Click
End Sub