When showing a userform (running its Show
method) it not only shows up on the screen but also takes the focus (the destination of e.g. keystrokes).
Say, the userform is a custom made toolbar. Its Show
fires in Workbook_Open()
but the form itself is used relatively rarely so we want the focus to go back to the main application window right after its appearance.
Unfortunately, it seems SetFocus
method is not valid for application objects.
So how is this done?
I suppose the solution for my example comes after
Private Sub Workbook_Open()
[...]
UserForm1.Show
In fact, there are two shortcuts you can use. Press Windows+M to minimize all the open windows and change focus to the desktop. To return focus to where you were last working, using Shift+Windows+M. Press Windows+D to minimize all the open windows and change focus to the desktop.
We can close the userform by using the “Unload Me” statement and “UserForm. Hide” statements. Even though both are slightly different from each other, it will serve our purpose eventually.
Reset UserForm To do this, we simply close the form and then reopen it. This is the easiest way to completely reset the form and go back to the original values for each control. The first line removes the UserForm and the second line makes it reappear.
To display the form on screen, set the Visible property to True or use the Show or ShowModal method. To hide the form, set Visible to False or use the Hide method.
i use this one :
AppActivate Application.caption
this resets the focus from a userform to your Excel Sheet.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With