Set focus back to the application window after showing userform

Greenberet picture Greenberet · Jan 20, 2015 · Viewed 46.7k times · Source

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

Answer

Patrick Lepelletier picture Patrick Lepelletier · Jan 21, 2015

i use this one :

AppActivate Application.caption

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