Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set focus back to the application window after showing userform

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
like image 638
Greenberet Avatar asked Jan 20 '15 10:01

Greenberet


People also ask

How do you change the focus on Excel?

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.

How do I cancel UserForm?

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.

How do I reset my UserForm?

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.

How do I make UserForm visible?

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.


1 Answers

i use this one :

AppActivate Application.caption

this resets the focus from a userform to your Excel Sheet.

like image 194
Patrick Lepelletier Avatar answered Nov 03 '22 00:11

Patrick Lepelletier